diff --git a/application/controllers/Config.php b/application/controllers/Config.php index cb06d8689..6cd5cb4c0 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -299,6 +299,7 @@ class Config extends Secure_Controller 'suggestions_second_column' => $this->input->post('suggestions_second_column'), 'suggestions_third_column' => $this->input->post('suggestions_third_column'), 'giftcard_number' => $this->input->post('giftcard_number'), + 'derive_sale_quantity' => $this->input->post('derive_sale_quantity') != NULL, 'statistics' => $this->input->post('statistics') != NULL, 'custom1_name' => $this->input->post('custom1_name'), 'custom2_name' => $this->input->post('custom2_name'), diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index b0a44c2b6..3b9523a12 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -464,10 +464,12 @@ class Sales extends Secure_Controller $quantity = parse_decimals($this->input->post('quantity')); $discount = parse_decimals($this->input->post('discount')); $item_location = $this->input->post('location'); + $total = $this->input->post('total') != '' ? $this->input->post('total') : NULL; + error_log('>>>Sales.php total-' . $total); if($this->form_validation->run() != FALSE) { - $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price); + $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price, $total); } else { diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index 3f7074a3a..48795b27c 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -88,6 +88,8 @@ $lang["config_default_tax_rate_1"] = "Tax 1 Rate"; $lang["config_default_tax_rate_2"] = "Tax 2 Rate"; $lang["config_default_tax_rate_number"] = "Default Tax Rate must be a number."; $lang["config_default_tax_rate_required"] = "Default Tax Rate is a required field."; +$lang["config_derive_sale_quantity"] = "Allow Derived Sale Quantity"; +$lang["config_derive_sale_quantity_tooltip"] = "If checked then a new item type will provided for items ordered by extended amount"; $lang["config_dinner_table"] = "Table"; $lang["config_dinner_table_duplicate"] = "Table must be unique."; $lang["config_dinner_table_enable"] = "Enable Dinner Tables"; diff --git a/application/language/en-US/items_lang.php b/application/language/en-US/items_lang.php index 5a36d6c73..1cb87640b 100644 --- a/application/language/en-US/items_lang.php +++ b/application/language/en-US/items_lang.php @@ -4,6 +4,7 @@ $lang["items_add_minus"] = "Inventory to add or subtract."; $lang["items_allow_alt_desciption"] = ""; $lang["items_allow_alt_description"] = "Allow Alternate Description"; $lang["items_amazon"] = "Amazon"; +$lang["items_amount_entry"] = "Amount Entry"; $lang["items_bulk_edit"] = "Bulk Edit"; $lang["items_buy_price_required"] = "Purchase Price is a required field."; $lang["items_cannot_be_deleted"] = "Could not delete selected Item(s), one or more of the selected Items have sales."; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index ad28bd603..eaeb617b1 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -807,6 +807,7 @@ class Sale_lib 'discounted_total' => $discounted_total, 'print_option' => $print_option_selected, 'stock_type' => $stock_type, + 'item_type' => $item_type, 'tax_category_id' => $item_info->tax_category_id ) ); @@ -882,12 +883,16 @@ class Sale_lib return -1; } - public function edit_item($line, $description, $serialnumber, $quantity, $discount, $price) + public function edit_item($line, $description, $serialnumber, $quantity, $discount, $price, $total=NULL) { $items = $this->get_cart(); if(isset($items[$line])) { $line = &$items[$line]; + if($total != NULL && $total != $line['total']) + { + $quantity = $this->get_quantity_sold($total, $price); + } $line['description'] = $description; $line['serialnumber'] = $serialnumber; $line['quantity'] = $quantity; @@ -1185,6 +1190,21 @@ class Sale_lib return $total; } + /** + * Derive the quantity sold based on the new total entered, returning the quanitity rounded to the + * appropriate decimal positions. + * @param $total + * @param $price + * @return string + */ + public function get_quantity_sold($total, $price) + { + + $quantity = bcdiv($total, $price, quantity_decimals()); + + return $quantity; + } + public function get_extended_amount($quantity, $price, $discount_amount = 0) { $extended_amount = bcmul($quantity, $price); diff --git a/application/migrations/sqlscripts/3.2.0_to_3.3.0.sql b/application/migrations/sqlscripts/3.2.0_to_3.3.0.sql new file mode 100644 index 000000000..d526ea8ef --- /dev/null +++ b/application/migrations/sqlscripts/3.2.0_to_3.3.0.sql @@ -0,0 +1,4 @@ +-- Add new config option to allow derive sale quantity feature + +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES +('derive_sale_quantity', '0'); diff --git a/application/models/Item.php b/application/models/Item.php index 82cd62e03..8cf8ea086 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -5,6 +5,7 @@ define('HAS_NO_STOCK', 1); define('ITEM', 0); define('ITEM_KIT', 1); +define('ITEM_AMOUNT_ENTRY', 2); define('PRINT_ALL', 0); define('PRINT_PRICED', 1); @@ -492,11 +493,12 @@ class Item extends CI_Model public function get_search_suggestions($search, $filters = array('is_deleted' => FALSE, 'search_custom' => FALSE), $unique = FALSE, $limit = 25) { $suggestions = array(); + $non_kit = array(ITEM, ITEM_AMOUNT_ENTRY); $this->db->select($this->get_search_suggestion_format('item_id, name')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->like('name', $search); $this->db->order_by('name', 'asc'); foreach($this->db->get()->result() as $row) @@ -507,7 +509,7 @@ class Item extends CI_Model $this->db->select($this->get_search_suggestion_format('item_id, item_number')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->like('item_number', $search); $this->db->order_by('item_number', 'asc'); foreach($this->db->get()->result() as $row) @@ -521,7 +523,7 @@ class Item extends CI_Model $this->db->select('category'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $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'); @@ -536,7 +538,7 @@ 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("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $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) @@ -548,7 +550,7 @@ class Item extends CI_Model $this->db->select($this->get_search_suggestion_format('item_id, name, description')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $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) @@ -577,7 +579,7 @@ class Item extends CI_Model $this->db->or_like('custom10', $search); $this->db->group_end(); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $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)); @@ -598,11 +600,12 @@ class Item extends CI_Model public function get_stock_search_suggestions($search, $filters = array('is_deleted' => FALSE, 'search_custom' => FALSE), $unique = FALSE, $limit = 25) { $suggestions = array(); + $non_kit = array(ITEM, ITEM_PRICE_BASED); $this->db->select($this->get_search_suggestion_format('item_id, name')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->like('name', $search); $this->db->order_by('name', 'asc'); @@ -614,7 +617,7 @@ class Item extends CI_Model $this->db->select($this->get_search_suggestion_format('item_id, item_number')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->like('item_number', $search); $this->db->order_by('item_number', 'asc'); @@ -629,7 +632,7 @@ class Item extends CI_Model $this->db->select('category'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->distinct(); $this->db->like('category', $search); @@ -656,7 +659,7 @@ class Item extends CI_Model $this->db->select($this->get_search_suggestion_format('item_id, name, description')); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->like('description', $search); $this->db->order_by('description', 'asc'); @@ -685,7 +688,7 @@ class Item extends CI_Model $this->db->or_like('custom9', $search); $this->db->or_like('custom10', $search); $this->db->group_end(); - $this->db->where("item_type = " . ITEM); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->where("stock_type = '0'"); // stocked items only $this->db->where('deleted', $filters['is_deleted']); foreach($this->db->get()->result() as $row) @@ -707,11 +710,12 @@ class Item extends CI_Model public function get_kit_search_suggestions($search, $filters = array('is_deleted' => FALSE, 'search_custom' => FALSE), $unique = FALSE, $limit = 25) { $suggestions = array(); + $non_kit = array(ITEM, ITEM_PRICE_BASED); $this->db->select('item_id, name'); $this->db->from('items'); $this->db->where('deleted', $filters['is_deleted']); - $this->db->where("item_type = " . ITEM_KIT); // standard, exclude kit items since kits will be picked up later + $this->db->where_in('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later $this->db->like('name', $search); $this->db->order_by('name', 'asc'); foreach($this->db->get()->result() as $row) diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 4e5ddd043..ceaa57323 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -172,7 +172,22 @@ -