From e994cd5444acaf87ccc26d58a48178edad7a924c Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Fri, 3 Oct 2014 10:33:34 +0200 Subject: [PATCH 1/3] Fix default location selected (now uses allowed locations only) --- application/libraries/Item_lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php index 4658391fe..843601cb1 100644 --- a/application/libraries/Item_lib.php +++ b/application/libraries/Item_lib.php @@ -13,8 +13,9 @@ class Item_lib { if(!$this->CI->session->userdata('item_location')) { - $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = $stock_locations[0]['location_id']; + $stock_locations = $this->CI->Stock_locations->get_allowed_locations(); + $key=current(array_keys($stock_locations)); + $location_name = $stock_locations[$key]['location_id']; $this->set_item_location($location_name); } return $this->CI->session->userdata('item_location'); From 5a4ac8dde36e068cfdb549abbd5defb2ddb1550b Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Fri, 3 Oct 2014 17:41:39 +0200 Subject: [PATCH 2/3] Fix comments in receivings --- application/controllers/receivings.php | 6 ++++++ application/libraries/Item_lib.php | 4 +--- application/libraries/Receiving_lib.php | 19 +++++++++++++++++-- application/libraries/Sale_lib.php | 3 +-- application/models/stock_locations.php | 12 ++++++++++++ application/views/receivings/receiving.php | 9 +++++++-- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index d4ae1eb05..ff164146e 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -51,6 +51,11 @@ class Receivings extends Secure_area } $this->_reload(); } + + function set_comment() + { + $this->receiving_lib->set_comment($this->input->post('comment')); + } function add() { @@ -251,6 +256,7 @@ class Receivings extends Secure_area $data['total']=$this->receiving_lib->get_total(); $data['items_module_allowed'] = $this->Employee->has_permission('items', $person_info->person_id); + $data['comment']=$this->receiving_lib->get_comment(); $data['payment_options']=array( $this->lang->line('sales_cash') => $this->lang->line('sales_cash'), $this->lang->line('sales_check') => $this->lang->line('sales_check'), diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php index 843601cb1..64f3c9853 100644 --- a/application/libraries/Item_lib.php +++ b/application/libraries/Item_lib.php @@ -13,9 +13,7 @@ class Item_lib { if(!$this->CI->session->userdata('item_location')) { - $stock_locations = $this->CI->Stock_locations->get_allowed_locations(); - $key=current(array_keys($stock_locations)); - $location_name = $stock_locations[$key]['location_id']; + $location_name = $this->Stock_locations->get_default_location(); $this->set_item_location($location_name); } return $this->CI->session->userdata('item_location'); diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index ca9351abc..24c603af1 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -52,12 +52,26 @@ class Receiving_lib { if(!$this->CI->session->userdata('recv_stock_source')) { - $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = $stock_locations[0]['location_id']; + $location_name = $this->Stock_locations->get_default_location(); $this->set_stock_source($location_name); } return $this->CI->session->userdata('recv_stock_source'); } + + function get_comment() + { + return $this->CI->session->userdata('comment'); + } + + function set_comment($comment) + { + $this->CI->session->set_userdata('comment', $comment); + } + + function clear_comment() + { + $this->CI->session->unset_userdata('comment'); + } function set_stock_source($stock_source) { @@ -294,6 +308,7 @@ class Receiving_lib $this->clear_mode(); $this->empty_cart(); $this->delete_supplier(); + $this->clear_comment(); } function get_item_total($quantity, $price, $discount_percentage) diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 2c0eb9096..139f9eb18 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -172,8 +172,7 @@ class Sale_lib { if(!$this->CI->session->userdata('sale_location')) { - $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = $stock_locations[0]['location_id']; + $location_name = $this->Stock_locations->get_default_location(); $this->set_sale_location($location_name); } return $this->CI->session->userdata('sale_location'); diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 2a8b21bc2..41bd24ce6 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -61,6 +61,18 @@ class Stock_locations extends CI_Model return $stock_locations; } + function get_default_location_name() + { + $this->db->from('stock_locations'); + // TODO replace with extra join on ospos_grants + $this->db->join('modules', 'modules.module_id=concat(\'items_stock\', location_id)'); + $this->db->join('permissions', 'permissions.module_id=modules.module_id'); + $this->db->where('person_id', $this->session->userdata('person_id')); + $this->db->where('deleted',0); + $this->db->limit(1); + return $this->db->get()->row()->location_name; + } + function get_location_name($location_id) { $this->db->from('stock_locations'); diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index 578fe5268..bb3111b19 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -196,7 +196,7 @@ else 'finish_sale_form')); ?>
- 'comment','value'=>'','rows'=>'4','cols'=>'23'));?> + 'comment','id'=>'comment','value'=>$comment,'rows'=>'4','cols'=>'23'));?>

".$this->lang->line('recvs_complete_receiving').""; @@ -218,7 +218,7 @@ else 'finish_sale_form')); ?>
- 'comment','value'=>'','rows'=>'4','cols'=>'23'));?> + 'comment','id'=>'comment','value'=>$comment,'rows'=>'4','cols'=>'23'));?>

lang->line('recvs_start_typing_supplier_name'); ?>"); }); + $('#comment').change(function() + { + $.post('', {comment: $('#comment').val()}); + }); + $("#finish_sale_button").click(function() { if (confirm('lang->line("recvs_confirm_finish_receiving"); ?>')) From 5e8367681bda5f3abcc592a89a0350852727b7cc Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Sat, 4 Oct 2014 13:38:52 +0200 Subject: [PATCH 3/3] Fix default location in items, sales and receivings --- application/controllers/items.php | 2 +- application/libraries/Item_lib.php | 2 +- application/libraries/Receiving_lib.php | 7 +++---- application/libraries/Sale_lib.php | 2 +- application/models/stock_locations.php | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/application/controllers/items.php b/application/controllers/items.php index 6b1a71a63..23e747b8c 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -19,7 +19,7 @@ class Items extends Secure_area implements iData_controller $stock_location=$this->item_lib->get_item_location(); $stock_locations=$this->Stock_locations->get_allowed_locations(); - $data['stock_location']=$this->item_lib->get_item_location(); + $data['stock_location']=$stock_location; $data['stock_locations']=$stock_locations; $data['controller_name']=strtolower(get_class()); diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php index 64f3c9853..9517000f9 100644 --- a/application/libraries/Item_lib.php +++ b/application/libraries/Item_lib.php @@ -13,7 +13,7 @@ class Item_lib { if(!$this->CI->session->userdata('item_location')) { - $location_name = $this->Stock_locations->get_default_location(); + $location_name = $this->CI->Stock_locations->get_default_location_id(); $this->set_item_location($location_name); } return $this->CI->session->userdata('item_location'); diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 24c603af1..f19f4042b 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -52,7 +52,7 @@ class Receiving_lib { if(!$this->CI->session->userdata('recv_stock_source')) { - $location_name = $this->Stock_locations->get_default_location(); + $location_name = $this->CI->Stock_locations->get_default_location_id(); $this->set_stock_source($location_name); } return $this->CI->session->userdata('recv_stock_source'); @@ -87,9 +87,8 @@ class Receiving_lib { if(!$this->CI->session->userdata('recv_stock_destination')) { - $stock_locations = $this->CI->Stock_locations->get_undeleted_all()->result_array(); - $location_name = $stock_locations[0]['location_id']; - $this->set_stock_destination($location_name); + $location_name = $this->CI->Stock_locations->get_default_location_id(); + $this->set_stock_destination($location_name); } return $this->CI->session->userdata('recv_stock_destination'); } diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 139f9eb18..174f6aa4b 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -172,7 +172,7 @@ class Sale_lib { if(!$this->CI->session->userdata('sale_location')) { - $location_name = $this->Stock_locations->get_default_location(); + $location_name = $this->CI->Stock_locations->get_default_location_id(); $this->set_sale_location($location_name); } return $this->CI->session->userdata('sale_location'); diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 41bd24ce6..f50adfa88 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -61,7 +61,7 @@ class Stock_locations extends CI_Model return $stock_locations; } - function get_default_location_name() + function get_default_location_id() { $this->db->from('stock_locations'); // TODO replace with extra join on ospos_grants @@ -70,7 +70,7 @@ class Stock_locations extends CI_Model $this->db->where('person_id', $this->session->userdata('person_id')); $this->db->where('deleted',0); $this->db->limit(1); - return $this->db->get()->row()->location_name; + return $this->db->get()->row()->location_id; } function get_location_name($location_id)