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/controllers/receivings.php b/application/controllers/receivings.php
index 33823c658..cd6e7f69f 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()
{
@@ -226,6 +231,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 4658391fe..9517000f9 100644
--- a/application/libraries/Item_lib.php
+++ b/application/libraries/Item_lib.php
@@ -13,8 +13,7 @@ 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'];
+ $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 ca9351abc..f19f4042b 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->CI->Stock_locations->get_default_location_id();
$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)
{
@@ -73,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');
}
@@ -294,6 +307,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..174f6aa4b 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->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 2a8b21bc2..f50adfa88 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_id()
+ {
+ $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_id;
+ }
+
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 8f377d8a7..6133e47c2 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'));?>