Class: DeliveriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/deliveries_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Methods included from PathHelper

#finance_group_transactions_path

Instance Method Details

#add_stock_changeObject



52
53
54
55
56
# File 'app/controllers/deliveries_controller.rb', line 52

def add_stock_change
  @stock_change = StockChange.new
  @stock_change.stock_article = StockArticle.find(params[:stock_article_id])
  render layout: false
end

#createObject



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/deliveries_controller.rb', line 22

def create
  @delivery = Delivery.new(params[:delivery])

  if @delivery.save
    flash[:notice] = I18n.t('deliveries.create.notice')
    redirect_to [@supplier, @delivery]
  else
    render action: 'new'
  end
end

#destroyObject



44
45
46
47
48
49
50
# File 'app/controllers/deliveries_controller.rb', line 44

def destroy
  @delivery = Delivery.find(params[:id])
  @delivery.destroy

  flash[:notice] = I18n.t('deliveries.destroy.notice')
  redirect_to supplier_deliveries_url(@supplier)
end

#editObject



18
19
20
# File 'app/controllers/deliveries_controller.rb', line 18

def edit
  @delivery = Delivery.find(params[:id])
end

#form_on_stock_article_createObject

See publish/subscribe design pattern in /doc.



58
59
60
61
62
# File 'app/controllers/deliveries_controller.rb', line 58

def form_on_stock_article_create # See publish/subscribe design pattern in /doc.
  @stock_article = StockArticle.find(params[:id])

  render layout: false
end

#form_on_stock_article_updateObject

See publish/subscribe design pattern in /doc.



64
65
66
67
68
# File 'app/controllers/deliveries_controller.rb', line 64

def form_on_stock_article_update # See publish/subscribe design pattern in /doc.
  @stock_article = StockArticle.find(params[:id])

  render layout: false
end

#indexObject



4
5
6
# File 'app/controllers/deliveries_controller.rb', line 4

def index
  @deliveries = @supplier.deliveries.order('date DESC')
end

#newObject



13
14
15
16
# File 'app/controllers/deliveries_controller.rb', line 13

def new
  @delivery = @supplier.deliveries.build
  @delivery.date = Date.today # TODO: move to model/database
end

#showObject



8
9
10
11
# File 'app/controllers/deliveries_controller.rb', line 8

def show
  @delivery = Delivery.find(params[:id])
  @stock_changes = @delivery.stock_changes.includes(:stock_article).order('articles.name ASC')
end

#updateObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/deliveries_controller.rb', line 33

def update
  @delivery = Delivery.find(params[:id])

  if @delivery.update(params[:delivery])
    flash[:notice] = I18n.t('deliveries.update.notice')
    redirect_to [@supplier, @delivery]
  else
    render action: 'edit'
  end
end