@@ -9,10 +9,7 @@ def quantity
99 end
1010
1111 def index
12- if Event . read_events? ( current_organization )
13- @inventory = View ::Inventory . new ( current_organization . id )
14- end
15-
12+ @inventory = View ::Inventory . new ( current_organization . id )
1613 @selected_item_category = filter_params [ :containing ]
1714 @items = StorageLocation . items_inventoried ( current_organization , @inventory )
1815 @include_inactive_storage_locations = params [ :include_inactive_storage_locations ] . present?
@@ -33,21 +30,7 @@ def index
3330 respond_to do |format |
3431 format . html
3532 format . csv do
36- if Event . read_events? ( current_organization )
37- send_data StorageLocation . generate_csv_from_inventory ( @storage_locations , @inventory ) , filename : "StorageLocations-#{ Time . zone . today } .csv"
38- else
39- active_inventory_item_names = [ ]
40- @storage_locations . each do |storage_location |
41- active_inventory_item_names <<
42- storage_location
43- . active_inventory_items
44- . joins ( :item )
45- . select ( 'distinct items.name' )
46- . pluck ( :name )
47- end
48- active_inventory_item_names = active_inventory_item_names . flatten . uniq . sort
49- send_data StorageLocation . generate_csv ( @storage_locations , active_inventory_item_names ) , filename : "StorageLocations-#{ Time . zone . today } .csv"
50- end
33+ send_data StorageLocation . generate_csv_from_inventory ( @storage_locations , @inventory ) , filename : "StorageLocations-#{ Time . zone . today } .csv"
5134 end
5235 end
5336 end
@@ -78,16 +61,14 @@ def show
7861 @items_out_total = ItemsOutTotalQuery . new ( organization : current_organization , storage_location : @storage_location ) . call
7962 @items_in = ItemsInQuery . new ( organization : current_organization , storage_location : @storage_location ) . call
8063 @items_in_total = ItemsInTotalQuery . new ( organization : current_organization , storage_location : @storage_location ) . call
81- if Event . read_events? ( current_organization )
82- if View ::Inventory . within_snapshot? ( current_organization . id , params [ :version_date ] )
83- @inventory = View ::Inventory . new ( current_organization . id , event_time : params [ :version_date ] )
84- else
85- @legacy_inventory = View ::Inventory . legacy_inventory_for_storage_location (
86- current_organization . id ,
87- @storage_location . id ,
88- params [ :version_date ]
89- )
90- end
64+ if View ::Inventory . within_snapshot? ( current_organization . id , params [ :version_date ] )
65+ @inventory = View ::Inventory . new ( current_organization . id , event_time : params [ :version_date ] )
66+ else
67+ @legacy_inventory = View ::Inventory . legacy_inventory_for_storage_location (
68+ current_organization . id ,
69+ @storage_location . id ,
70+ params [ :version_date ]
71+ )
9172 end
9273
9374 respond_to do |format |
@@ -154,22 +135,10 @@ def destroy
154135 end
155136
156137 def inventory
157- if Event . read_events? ( current_organization )
158- @items = View ::Inventory . items_for_location ( StorageLocation . find ( params [ :id ] ) ,
159- include_omitted : params [ :include_omitted_items ] == "true" )
160- respond_to do |format |
161- format . json { render :event_inventory }
162- end
163- else
164- @inventory_items = current_organization . storage_locations
165- . includes ( inventory_items : :item )
166- . find ( params [ :id ] )
167- . inventory_items
168- . active
169-
170- @inventory_items += include_omitted_items ( @inventory_items . collect ( &:item_id ) ) if params [ :include_omitted_items ] == "true"
171- @inventory_items . to_a . sort_by! { |inventory_item | inventory_item . item . name . downcase }
172- respond_to :json
138+ @items = View ::Inventory . items_for_location ( StorageLocation . find ( params [ :id ] ) ,
139+ include_omitted : params [ :include_omitted_items ] == "true" )
140+ respond_to do |format |
141+ format . json { render :event_inventory }
173142 end
174143 end
175144
0 commit comments