Class: Cats::Core::StacksController
  
  
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods included from Common
  #create, #show, #update
  
  
  
  
  
  
  
  
  
  
  #authenticate, #current_user, #skip_bullet
  
  
    Instance Method Details
    
      
  
  
    #destroy  ⇒ Object 
  
  
  
  
    
      
43
44
45
46
47
48
49 
     | 
    
      # File 'app/controllers/cats/core/stacks_controller.rb', line 43
def destroy
  stack = set_object
  stack.destroy_stack
  render json: {success: true, data: serialize(stack)}
rescue StandardError => e
  render json: {success: false, error: e}
end
     | 
  
 
    
      
  
  
    #dispatch_stacks  ⇒ Object 
  
  
  
  
    
      
23
24
25
26
27
28
29
30
31
32
33
34 
     | 
    
      # File 'app/controllers/cats/core/stacks_controller.rb', line 23
def dispatch_stacks
  service = StackService.new
  dispatch = Dispatch.find(params[:id])
  stacks = service.dispatch_stacks(dispatch)
    if current_user.details.key?("stores")
    stores = current_user.details["stores"]
    stacks = stacks.select { |stack| stores.include?(stack.store_id) }
  end
  render json: {success: true, data: serialize(stacks)}
end
     | 
  
 
    
      
  
  
    #filter  ⇒ Object 
  
  
  
  
    
      
12
13
14
15 
     | 
    
      # File 'app/controllers/cats/core/stacks_controller.rb', line 12
def filter
  query = Stack.includes(:commodity, :unit).where(store_id: params[:id]).ransack(params[:q])
  render json: {success: true, data: serialize(query.result)}
end
     | 
  
 
    
      
  
  
    #index  ⇒ Object 
  
  
  
  
    
      
6
7
8
9
10 
     | 
    
      # File 'app/controllers/cats/core/stacks_controller.rb', line 6
def index
  super do
    Stack.includes(:commodity, :unit).where(store_id: params[:id])
  end
end
     | 
  
 
    
      
  
  
    #items_for_location  ⇒ Object 
  
  
  
  
    
      
17
18
19
20
21 
     | 
    
      # File 'app/controllers/cats/core/stacks_controller.rb', line 17
def items_for_location
  service = StackService.new
  commodities = service.items_for_location(current_user)
  render json: {success: true, data: serialize(commodities)}
end
     | 
  
 
    
      
  
  
    #receipt_stacks  ⇒ Object 
  
  
  
  
    
      
36
37
38
39
40
41 
     | 
    
      # File 'app/controllers/cats/core/stacks_controller.rb', line 36
def receipt_stacks
  service = StackService.new
  authorization = ReceiptAuthorization.find(params[:id])
  stacks = service.receipt_stacks(authorization.id)
  render json: {success: true, data: serialize(stacks)}
end
     |