From 3594c348ee8f863f6235926b02e653d82b1ad186 Mon Sep 17 00:00:00 2001 From: jekkos-t520 Date: Tue, 10 Feb 2015 16:04:52 +0100 Subject: [PATCH] Fix stock location permissions for github issue #34 --- application/controllers/receivings.php | 6 +++--- application/controllers/sales.php | 6 +++--- application/models/stock_locations.php | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 6afae835a..5962d861b 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -178,7 +178,7 @@ class Receivings extends Secure_area $data['receipt_title']=$this->lang->line('recvs_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a'); $data['mode']=$this->receiving_lib->get_mode(); - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations = $this->Stock_locations->get_undeleted_all('receivings')->result_array(); $data['show_stock_locations'] = count($stock_locations) > 1; $supplier_id=$this->receiving_lib->get_supplier(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; @@ -279,7 +279,7 @@ class Receivings extends Secure_area $data['mode']=$this->receiving_lib->get_mode(); $data['receipt_title']=$this->lang->line('recvs_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a', strtotime($receiving_info['receiving_time'])); - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations = $this->Stock_locations->get_undeleted_all('receivings')->result_array(); $data['show_stock_locations'] = count($stock_locations) > 1; $supplier_id=$this->receiving_lib->get_supplier(); $emp_info=$this->Employee->get_info($receiving_info['employee_id']); @@ -307,7 +307,7 @@ class Receivings extends Secure_area $data['modes']=array('receive'=>$this->lang->line('recvs_receiving'),'return'=>$this->lang->line('recvs_return')); $data['mode']=$this->receiving_lib->get_mode(); - $data['stock_locations']=$this->Stock_locations->get_allowed_locations(); + $data['stock_locations']=$this->Stock_locations->get_allowed_locations('receivings'); $show_stock_locations = count($data['stock_locations']) > 1; if ($show_stock_locations) { diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 1e72a5281..dbab47e67 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -216,7 +216,7 @@ class Sales extends Secure_area $data['total']=$this->sale_lib->get_total(); $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a'); - $stock_locations=$this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations=$this->Stock_locations->get_undeleted_all('sales')->result_array(); $data['show_stock_locations']=count($stock_locations) > 1; $customer_id=$this->sale_lib->get_customer(); $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; @@ -302,7 +302,7 @@ class Sales extends Secure_area { $sale_info = $this->Sale->get_info($sale_id)->row_array(); $this->sale_lib->copy_entire_sale($sale_id); - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); + $stock_locations = $this->Stock_locations->get_undeleted_all('sales')->result_array(); $data['show_stock_locations'] = count($stock_locations) > 1; $data['cart']=$this->sale_lib->get_cart(); $data['payments']=$this->sale_lib->get_payments(); @@ -424,7 +424,7 @@ class Sales extends Secure_area $data['modes']=array('sale'=>$this->lang->line('sales_sale'),'return'=>$this->lang->line('sales_return')); $data['mode']=$this->sale_lib->get_mode(); - $data['stock_locations']=$this->Stock_locations->get_allowed_locations(); + $data['stock_locations']=$this->Stock_locations->get_allowed_locations('sales'); $data['stock_location']=$this->sale_lib->get_sale_location(); $data['subtotal']=$this->sale_lib->get_subtotal(); diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index c4f70b6f6..6eb5203ca 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -18,19 +18,20 @@ class Stock_locations extends CI_Model return $this->db->get(); } - function get_undeleted_all() + function get_undeleted_all($module_id='items') { $this->db->from('stock_locations'); $this->db->join('permissions','permissions.location_id=stock_locations.location_id'); $this->db->join('grants','grants.permission_id=permissions.permission_id'); $this->db->where('person_id', $this->session->userdata('person_id')); + $this->db->like('permissions.permission_id', $module_id, 'after'); $this->db->where('deleted',0); return $this->db->get(); } - function get_allowed_locations() + function get_allowed_locations($module_id='items') { - $stock = $this->get_undeleted_all()->result_array(); + $stock = $this->get_undeleted_all($module_id)->result_array(); $stock_locations = array(); foreach($stock as $location_data) {