From fa3e28db5203b18ecd19008977f8f3bdb7a072f4 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Fri, 5 Jul 2013 20:13:55 +0000 Subject: [PATCH] Commit changes to models that reflect code additions git-svn-id: svn+ssh://jekkos@svn.code.sf.net/p/opensourcepos/code/@68 c3eb156b-1dc0-44e1-88ae-e38439141b53 --- application/models/customer.php | 1 - application/models/giftcard.php | 74 +++++++- application/models/item.php | 309 +++++++++++++++++++++++++++++++- application/models/person.php | 32 ++++ 4 files changed, 398 insertions(+), 18 deletions(-) diff --git a/application/models/customer.php b/application/models/customer.php index 9c083ea5d..8b0e54913 100644 --- a/application/models/customer.php +++ b/application/models/customer.php @@ -183,7 +183,6 @@ class Customer extends Person $suggestions = array_slice($suggestions, 0,$limit); } return $suggestions; - } /* diff --git a/application/models/giftcard.php b/application/models/giftcard.php index 4edad6a9f..c081858da 100644 --- a/application/models/giftcard.php +++ b/application/models/giftcard.php @@ -20,6 +20,7 @@ class Giftcard extends CI_Model function get_all($limit=10000, $offset=0) { $this->db->from('giftcards'); + $this->db->join('people','people.person_id=giftcards.person_id');//GARRISON ADDED 4/25/2013 $this->db->where('deleted',0); $this->db->order_by("giftcard_number", "asc"); $this->db->limit($limit); @@ -155,29 +156,84 @@ class Giftcard extends CI_Model $this->db->where('deleted',0); $this->db->order_by("giftcard_number", "asc"); $by_number = $this->db->get(); + foreach($by_number->result() as $row) { $suggestions[]=$row->giftcard_number; } - //only return $limit suggestions +/** GARRISON MODIFIED 4/24/2013 **/ + $this->db->from('customers'); + $this->db->join('people','customers.person_id=people.person_id'); + $this->db->like("first_name",$this->db->escape_like_str($search)); + $this->db->or_like("last_name",$this->db->escape_like_str($search)); + $this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search)); + $this->db->where("deleted","0"); + $this->db->order_by("last_name", "asc"); + $by_name = $this->db->get(); + + foreach($by_name->result() as $row) + { + $suggestions[]=$row->first_name.' '.$row->last_name; + } +/** END GARRISON MODIFIED **/ + + //only return $limit suggestions if(count($suggestions > $limit)) { $suggestions = array_slice($suggestions, 0,$limit); } return $suggestions; - } - + + /** GARRISON ADDED 5/3/2013 **/ + /* + Get search suggestions to find customers + */ + function get_person_search_suggestions($search,$limit=25) + { + $suggestions = array(); + + $this->db->select('person_id'); + $this->db->from('people'); + $this->db->like('person_id',$this->db->escape_like_str($search)); + $this->db->or_like('first_name',$this->db->escape_like_str($search)); + $this->db->or_like('last_name',$this->db->escape_like_str($search)); + $this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search)); + $this->db->or_like('email',$this->db->escape_like_str($search)); + $this->db->or_like('phone_number',$this->db->escape_like_str($search)); + $this->db->order_by('person_id', 'asc'); + $by_person_id = $this->db->get(); + + foreach($by_person_id->result() as $row) + { + $suggestions[]=$row->person_id; + } + + //only return $limit suggestions + if(count($suggestions > $limit)) + { + $suggestions = array_slice($suggestions, 0,$limit); + } + return $suggestions; + } + +/** GARRISON MODIFIED 4/24/2013 **/ /* Preform a search on giftcards */ - function search($search) - { - $this->db->from('giftcards'); - $this->db->where("giftcard_number LIKE '%".$this->db->escape_like_str($search)."%' and deleted=0"); - $this->db->order_by("giftcard_number", "asc"); - return $this->db->get(); + function search($search) + { + $this->db->from('giftcards'); + $this->db->join('people','giftcards.person_id=people.person_id'); + $this->db->like("first_name",$this->db->escape_like_str($search)); + $this->db->or_like("last_name",$this->db->escape_like_str($search)); + $this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search)); + $this->db->or_like("giftcard_number",$this->db->escape_like_str($search)); + $this->db->or_like("giftcards.person_id",$this->db->escape_like_str($search)); + $this->db->where('deleted',$this->db->escape('0')); + $this->db->order_by("giftcard_number", "asc"); + return $this->db->get(); } public function get_giftcard_value( $giftcard_number ) diff --git a/application/models/item.php b/application/models/item.php index 23a6dc9b8..00a5b640d 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -33,7 +33,7 @@ class Item extends CI_Model return $this->db->count_all_results(); } - function get_all_filtered($low_inventory=0,$is_serialized=0,$no_description) + function get_all_filtered($low_inventory=0,$is_serialized=0,$no_description,$search_custom)/**GARRISON MODIFIED 4/21/2013**/ { $this->db->from('items'); if ($low_inventory !=0 ) @@ -48,6 +48,22 @@ class Item extends CI_Model { $this->db->where('description',''); } +/**GARRISON SECTION ADDED 4/21/2013**/ +/** + if ($search_custom!=0 ) + { + $this->db->like('custom1',$search); + $this->db->or_like('custom2',$search); + $this->db->or_like('custom3',$search); + $this->db->or_like('custom4',$search); + $this->db->or_like('custom5',$search); + $this->db->or_like('custom6',$search); + $this->db->or_like('custom7',$search); + $this->db->or_like('custom8',$search); + $this->db->or_like('custom9',$search); + $this->db->or_like('custom10',$search); + } +**/ $this->db->where('deleted',0); $this->db->order_by("name", "asc"); return $this->db->get(); @@ -197,9 +213,42 @@ class Item extends CI_Model { $suggestions[]=$row->item_number; } +/** GARRISON ADDED 4/21/2013 **/ + //Search by description + $this->db->from('items'); + $this->db->like('description', $search); + $this->db->where('deleted',0); + $this->db->order_by("description", "asc"); + $by_name = $this->db->get(); + foreach($by_name->result() as $row) + { + $suggestions[]=$row->name; + } +/** END GARRISON ADDED **/ - - //only return $limit suggestions +/** GARRISON ADDED 4/22/2013 **/ + //Search by custom fields + $this->db->from('items'); + $this->db->like('custom1', $search); + $this->db->or_like('custom2', $search); + $this->db->or_like('custom3', $search); + $this->db->or_like('custom4', $search); + $this->db->or_like('custom5', $search); + $this->db->or_like('custom6', $search); + $this->db->or_like('custom7', $search); + $this->db->or_like('custom8', $search); + $this->db->or_like('custom9', $search); + $this->db->or_like('custom10', $search); + $this->db->where('deleted',0); + $this->db->order_by("name", "asc"); + $by_name = $this->db->get(); + foreach($by_name->result() as $row) + { + $suggestions[]=$row->name; + } +/** END GARRISON ADDED **/ + + //only return $limit suggestions if(count($suggestions > $limit)) { $suggestions = array_slice($suggestions, 0,$limit); @@ -231,14 +280,46 @@ class Item extends CI_Model { $suggestions[]=$row->item_id.'|'.$row->item_number; } - +/** GARRISON ADDED 4/21/2013 **/ + //Search by description + $this->db->from('items'); + $this->db->where('deleted',0); + $this->db->like('description', $search); + $this->db->order_by("description", "asc"); + $by_description = $this->db->get(); + foreach($by_description->result() as $row) + { + $suggestions[]=$row->item_id.'|'.$row->name; + } +/** END GARRISON ADDED **/ + /** GARRISON ADDED 4/22/2013 **/ + //Search by custom fields + $this->db->from('items'); + $this->db->where('deleted',0); + $this->db->like('custom1', $search); + $this->db->or_like('custom2', $search); + $this->db->or_like('custom3', $search); + $this->db->or_like('custom4', $search); + $this->db->or_like('custom5', $search); + $this->db->or_like('custom6', $search); + $this->db->or_like('custom7', $search); + $this->db->or_like('custom8', $search); + $this->db->or_like('custom9', $search); + $this->db->or_like('custom10', $search); + $this->db->order_by("name", "asc"); + $by_description = $this->db->get(); + foreach($by_description->result() as $row) + { + $suggestions[]=$row->item_id.'|'.$row->name; + } + /** END GARRISON ADDED **/ + //only return $limit suggestions if(count($suggestions > $limit)) { $suggestions = array_slice($suggestions, 0,$limit); } return $suggestions; - } function get_category_suggestions($search) @@ -259,15 +340,227 @@ class Item extends CI_Model return $suggestions; } +/** GARRISON ADDED 5/18/2013 **/ + function get_location_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('location'); + $this->db->from('items'); + $this->db->like('location', $search); + $this->db->where('deleted', 0); + $this->db->order_by("location", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->location; + } + + return $suggestions; + } + + function get_custom1_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom1'); + $this->db->from('items'); + $this->db->like('custom1', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom1", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom1; + } + + return $suggestions; + } + + function get_custom2_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom2'); + $this->db->from('items'); + $this->db->like('custom2', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom2", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom2; + } + + return $suggestions; + } + + function get_custom3_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom3'); + $this->db->from('items'); + $this->db->like('custom3', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom3", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom3; + } + + return $suggestions; + } + + function get_custom4_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom4'); + $this->db->from('items'); + $this->db->like('custom4', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom4", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom4; + } + + return $suggestions; + } + + function get_custom5_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom5'); + $this->db->from('items'); + $this->db->like('custom5', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom5", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom5; + } + + return $suggestions; + } + + function get_custom6_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom6'); + $this->db->from('items'); + $this->db->like('custom6', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom6", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom6; + } + + return $suggestions; + } + + function get_custom7_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom7'); + $this->db->from('items'); + $this->db->like('custom7', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom7", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom7; + } + + return $suggestions; + } + + function get_custom8_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom8'); + $this->db->from('items'); + $this->db->like('custom8', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom8", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom8; + } + + return $suggestions; + } + + function get_custom9_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom9'); + $this->db->from('items'); + $this->db->like('custom9', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom9", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom9; + } + + return $suggestions; + } + + function get_custom10_suggestions($search) + { + $suggestions = array(); + $this->db->distinct(); + $this->db->select('custom10'); + $this->db->from('items'); + $this->db->like('custom10', $search); + $this->db->where('deleted', 0); + $this->db->order_by("custom10", "asc"); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[]=$row->custom10; + } + + return $suggestions; + } +/** END GARRISON ADDED **/ /* Preform a search on items */ function search($search) { $this->db->from('items'); - $this->db->where("(name LIKE '%".$this->db->escape_like_str($search)."%' or - item_number LIKE '%".$this->db->escape_like_str($search)."%' or - category LIKE '%".$this->db->escape_like_str($search)."%') and deleted=0"); + $this->db->where("( + name LIKE '%".$this->db->escape_like_str($search)."%' or + item_number LIKE '%".$this->db->escape_like_str($search)."%' or + description LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/21/2013**/ + custom1 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom2 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom3 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom4 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom5 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom6 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom7 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom8 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom9 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + custom10 LIKE '%".$this->db->escape_like_str($search)."%' or/**GARRISON ADDED 4/22/2013**/ + category LIKE '%".$this->db->escape_like_str($search)."%') and + deleted=0"); $this->db->order_by("name", "asc"); return $this->db->get(); } diff --git a/application/models/person.php b/application/models/person.php index f906cf063..d44f52456 100644 --- a/application/models/person.php +++ b/application/models/person.php @@ -84,6 +84,38 @@ class Person extends CI_Model $this->db->where('person_id', $person_id); return $this->db->update('people',$person_data); } +/** GARRISON ADDED 4/25/2013 IN PROGRESS **/ + /* + Get search suggestions to find customers + */ + function get_search_suggestions($search,$limit=25) + { + $suggestions = array(); + +// $this->db->select("person_id"); +// $this->db->from('people'); +// $this->db->where('deleted',0); +// $this->db->where('person_id',$this->db->escape($search)); +// $this->db->like('first_name',$this->db->escape_like_str($search)); +// $this->db->or_like('last_name',$this->db->escape_like_str($search)); +// $this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search)); +// $this->db->or_like('email',$search); +// $this->db->or_like('phone_number',$search); +// $this->db->order_by('last_name', "asc"); + $by_person_id = $this->db->get(); + + foreach($by_person_id->result() as $row) + { + $suggestions[]=$row->person_id; + } + + //only return $limit suggestions + if(count($suggestions > $limit)) + { + $suggestions = array_slice($suggestions, 0,$limit); + } + return $suggestions; + } /* Deletes one Person (doesn't actually do anything)