From 5a4ac8dde36e068cfdb549abbd5defb2ddb1550b Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Fri, 3 Oct 2014 17:41:39 +0200 Subject: [PATCH] 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"); ?>'))