diff --git a/application/controllers/items.php b/application/controllers/items.php index 4526148d6..6b1a71a63 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -6,6 +6,7 @@ class Items extends Secure_area implements iData_controller function __construct() { parent::__construct('items'); + $this->load->library('item_lib'); } function index() @@ -16,9 +17,14 @@ class Items extends Secure_area implements iData_controller $config['uri_segment'] = 3; $this->pagination->initialize($config); + $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_locations']=$stock_locations; + $data['controller_name']=strtolower(get_class()); $data['form_width']=$this->get_form_width(); - $data['manage_table']=get_items_manage_table( $this->Item->get_all( $config['per_page'], $this->uri->segment( $config['uri_segment'] ) ), $this ); + $data['manage_table']=get_items_manage_table( $this->Item->get_all( $stock_location, $config['per_page'], $this->uri->segment( $config['uri_segment'] ) ), $this ); $this->load->view('items/manage',$data); } @@ -27,7 +33,13 @@ class Items extends Secure_area implements iData_controller $is_serialized=$this->input->post('is_serialized'); $no_description=$this->input->post('no_description'); $search_custom=$this->input->post('search_custom');//GARRISON ADDED 4/13/2013 - $is_deleted=$this->input->post('is_deleted'); // Parq 131215 + $is_deleted=$this->input->post('is_deleted'); // Parq 131215 + $this->item_lib->set_item_location($this->input->post('stock_location')); + + $stock_location=$this->input->post('stock_location'); + $stock_locations=$this->Stock_locations->get_allowed_locations(); + $data['stock_location']=$this->item_lib->get_item_location(); + $data['stock_locations']=$stock_locations; $data['search_section_state']=$this->input->post('search_section_state'); $data['is_serialized']=$this->input->post('is_serialized'); @@ -36,7 +48,7 @@ class Items extends Secure_area implements iData_controller $data['is_deleted']=$this->input->post('is_deleted'); // Parq 131215 $data['controller_name']=strtolower(get_class()); $data['form_width']=$this->get_form_width(); - $data['manage_table']=get_items_manage_table($this->Item->get_all_filtered($is_serialized,$no_description,$search_custom,$is_deleted),$this);//GARRISON MODIFIED 4/13/2013, Parq 131215 + $data['manage_table']=get_items_manage_table($this->Item->get_all_filtered($stock_location,$is_serialized,$no_description,$search_custom,$is_deleted),$this);//GARRISON MODIFIED 4/13/2013, Parq 131215 $this->load->view('items/manage',$data); } @@ -182,13 +194,15 @@ class Items extends Secure_area implements iData_controller function get_row() { $item_id = $this->input->post('row_id'); - $data_row=get_item_data_row($this->Item->get_info($item_id),$this); + $stock_location_id=$this->item_lib->get_item_location(); + $data_row=get_item_data_row($this->Item->get_info($item_id,$stock_location_id),$this); echo $data_row; } function view($item_id=-1) { - $data['item_info']=$this->Item->get_info($item_id); + $stock_location_id=$this->item_lib->get_item_location(); + $data['item_info']=$this->Item->get_info($item_id,$stock_location_id); $data['item_tax_info']=$this->Item_taxes->get_info($item_id); $suppliers = array('' => $this->lang->line('items_none')); foreach($this->Supplier->get_all()->result_array() as $row) @@ -197,20 +211,19 @@ class Items extends Secure_area implements iData_controller } $data['suppliers']=$suppliers; - $data['selected_supplier'] = $this->Item->get_info($item_id)->supplier_id; + $data['selected_supplier'] = $this->Item->get_info($item_id,$stock_location_id)->supplier_id; $data['default_tax_1_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_1_rate') : ''; $data['default_tax_2_rate']=($item_id==-1) ? $this->Appconfig->get('default_tax_2_rate') : ''; $locations_data = $this->Stock_locations->get_undeleted_all()->result_array(); - $location_array; foreach($locations_data as $location) { $quantity = $this->Item_quantities->get_item_quantity($item_id, $location['location_id'])->quantity; $quantity = ($item_id == -1) ? null: $quantity; $location_array[$location['location_id']] = array('location_name'=>$location['location_name'], 'quantity'=>$quantity); + $data['stock_locations']= $location_array; } - $data['stock_locations']= $location_array; $this->load->view("items/form",$data); } diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 55b6edd3c..f5432f50c 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -361,17 +361,8 @@ 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'] = array(); - $stock_locations = $this->Stock_locations->get_undeleted_all()->result_array(); - $show_stock_locations = count($stock_locations) > 1; - if ($show_stock_locations) { - foreach($stock_locations as $location_data) - { - $data['stock_locations'][$location_data['location_id']] = $location_data['location_name']; - } - $data['stock_location']=$this->sale_lib->get_sale_location(); - } - $data['show_stock_locations'] = $show_stock_locations; + $data['stock_locations']=$this->Stock_locations->get_allowed_locations(); + $data['stock_location']=$this->sale_lib->get_sale_location(); $data['subtotal']=$this->sale_lib->get_subtotal(); $data['taxes']=$this->sale_lib->get_taxes(); diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index dd1f5751e..b4189612c 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -211,7 +211,7 @@ function get_item_data_row($item,$controller) $width = $controller->get_form_width(); $item_quantity=''; - $locations_data = $CI->Stock_locations->get_undeleted_all()->result_array(); + /* $locations_data = $CI->Stock_locations->get_allowed_locations()->result_array(); foreach($locations_data as $location) { if (count($locations_data) > 1) @@ -219,7 +219,7 @@ function get_item_data_row($item,$controller) $item_quantity .= $location['location_name'].': '; } $item_quantity .= $CI->Item_quantities->get_item_quantity($item->item_id, $location['location_id'])->quantity . '
'; - } + } */ $table_data_row=''; $table_data_row.=""; @@ -228,7 +228,7 @@ function get_item_data_row($item,$controller) $table_data_row.=''.$item->category.''; $table_data_row.=''.to_currency($item->cost_price).''; $table_data_row.=''.to_currency($item->unit_price).''; - $table_data_row.=''.$item_quantity.''; + $table_data_row.=''.$item->quantity.''; $table_data_row.=''.$tax_percents.''; $table_data_row.=''.anchor($controller_name."/view/$item->item_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).''; diff --git a/application/libraries/Item_lib.php b/application/libraries/Item_lib.php new file mode 100644 index 000000000..4658391fe --- /dev/null +++ b/application/libraries/Item_lib.php @@ -0,0 +1,34 @@ +CI =& get_instance(); + } + + function get_item_location() + { + 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']; + $this->set_item_location($location_name); + } + return $this->CI->session->userdata('item_location'); + } + + function set_item_location($location) + { + $this->CI->session->set_userdata('item_location',$location); + } + + function clear_item_location() + { + $this->CI->session->unset_userdata('item_location'); + } +} + +?> diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 5b58023b1..89b4270cc 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -1,4 +1,5 @@ CI->Item->get_info($item_id); + $item_info=$this->CI->Item->get_info($item_id,$item_location); //array records are identified by $insertkey and item_id is just another field. $item = array(($insertkey)=> array( diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 5736df515..4371c44ab 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -231,7 +231,7 @@ class Sale_lib } $insertkey=$maxkey+1; - $item_info=$this->CI->Item->get_info($item_id); + $item_info=$this->CI->Item->get_info($item_id,$item_location); //array/cart records are identified by $insertkey and item_id is just another field. $item = array(($insertkey)=> array( diff --git a/application/models/item.php b/application/models/item.php index 2a5347118..a566bc3e9 100644 --- a/application/models/item.php +++ b/application/models/item.php @@ -16,11 +16,13 @@ class Item extends CI_Model /* Returns all the items */ - function get_all($limit=10000, $offset=0) + function get_all($stock_location_id,$limit=10000,$offset=0) { $this->db->from('items'); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); $this->db->where('deleted',0); - $this->db->order_by("name", "asc"); + $this->db->where('location_id',$stock_location_id); + $this->db->order_by("name","asc"); $this->db->limit($limit); $this->db->offset($offset); return $this->db->get(); @@ -33,9 +35,11 @@ class Item extends CI_Model return $this->db->count_all_results(); } - function get_all_filtered($is_serialized=0,$no_description,$search_custom,$is_deleted)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ + function get_all_filtered($stock_location_id,$is_serialized=0,$no_description,$search_custom,$is_deleted)/**GARRISON MODIFIED 4/21/2013, Parq 131215 **/ { $this->db->from('items'); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); + $this->db->where('location_id',$stock_location_id); if ($is_serialized !=0 ) { $this->db->where('is_serialized',1); @@ -62,14 +66,7 @@ class Item extends CI_Model $this->db->or_like('custom10',$search); } **/ -/* Parq 131215 start*/ - if ($is_deleted !=0 ) - { - $this->db->where('deleted',1); - } else { - $this->db->where('deleted',0); - } -/* Parq 131215 end*/ + $this->db->where('deleted',$is_deleted); $this->db->order_by("name", "asc"); return $this->db->get(); } @@ -77,10 +74,15 @@ class Item extends CI_Model /* Gets information about a particular item */ - function get_info($item_id) + function get_info($item_id,$stock_location_id=0) { $this->db->from('items'); - $this->db->where('item_id',$item_id); + $this->db->join('item_quantities','item_quantities.item_id=items.item_id'); + if ($stock_location_id > 0) + { + $this->db->where('location_id',$stock_location_id); + } + $this->db->where('items.item_id',$item_id); $query = $this->db->get(); diff --git a/application/models/stock_locations.php b/application/models/stock_locations.php index 9e73d5e13..e1f78ca0a 100644 --- a/application/models/stock_locations.php +++ b/application/models/stock_locations.php @@ -40,18 +40,27 @@ class Stock_locations extends CI_Model return $this->db->get()->row(); } - function get_undeleted_all($limit=10000, $offset=0) + function get_undeleted_all() { $this->db->from('stock_locations'); $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($limit); - $this->db->offset($offset); return $this->db->get(); } + function get_allowed_locations() + { + $stock = $this->get_undeleted_all()->result_array(); + $stock_locations = array(); + foreach($stock as $location_data) + { + $stock_locations[$location_data['location_id']] = $location_data['location_name']; + } + return $stock_locations; + } + function get_location_name($location_id) { $this->db->from('stock_locations'); diff --git a/application/views/items/manage.php b/application/views/items/manage.php index 0a36e1f47..5a0abbee2 100644 --- a/application/views/items/manage.php +++ b/application/views/items/manage.php @@ -152,6 +152,12 @@ function show_hide_search_filter(search_filter_section, switchImgTag) {
  • lang->line("common_delete"),array('id'=>'delete')); ?>
  • lang->line("items_bulk_edit"),array('id'=>'bulk_edit','title'=>$this->lang->line('items_edit_multiple_items'))); ?>
  • lang->line("items_generate_barcodes"),array('id'=>'generate_barcodes', 'target' =>'_blank','title'=>$this->lang->line('items_generate_barcodes'))); ?>
  • + 1): ?> +
  • + 'stock_filter_form')); ?> + +
  • +
  • spinner 'search_form')); ?> diff --git a/application/views/reports/graphical.php b/application/views/reports/graphical.php index a54fca8d9..847f70505 100644 --- a/application/views/reports/graphical.php +++ b/application/views/reports/graphical.php @@ -1,6 +1,5 @@ load->view("partial/header"); -var_dump($data_file); ?>
    diff --git a/application/views/sales/register.php b/application/views/sales/register.php index d22ba61ef..599f308ea 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -20,7 +20,7 @@ if (isset($success)) 'mode_form')); ?> lang->line('sales_mode') ?> - + 0): ?> lang->line('sales_stock_location') ?> diff --git a/css/general.css b/css/general.css index 19629b365..41cd7ddfd 100644 --- a/css/general.css +++ b/css/general.css @@ -145,6 +145,11 @@ input#search padding: 0px; } +select#stock_location +{ + border: none; +} + #select_customer_form input, #select_supplier_form input { width: 95%; diff --git a/css/tables.css b/css/tables.css index a584c61a7..7457dd9b7 100644 --- a/css/tables.css +++ b/css/tables.css @@ -26,7 +26,7 @@ } -#table_action_header ul li span +#table_action_header ul li span a { background-color:#0a6184; border:2px solid #DDDDDD;