Class: PurchasesController

Inherits:
AdminController show all
Defined in:
app/controllers/purchases_controller.rb

Instance Method Summary collapse

Methods inherited from AdminController

#clean_search, #require_admin

Methods inherited from OfficeController

#error

Methods included from OfficeHelper

#best_euros, #current_basket, #current_basket_or_nil, #current_clerk, #date, #euros, #has_ssl?, #markdown, #new_basket, #paginate, #shipping_method

Instance Method Details

#createObject



50
51
52
53
54
55
56
57
# File 'app/controllers/purchases_controller.rb', line 50

def create
  @purchase = Purchase.create(params_for_model)
  if @purchase.save
    redirect_to purchase_path(@purchase), :notice => t(:create_success, :model => "purchase")
  else
    render :show
  end
end

#editObject



46
47
48
# File 'app/controllers/purchases_controller.rb', line 46

def edit

end

#indexObject

Uncomment for check abilities with CanCan authorize_resource



9
10
11
12
13
# File 'app/controllers/purchases_controller.rb', line 9

def index
  @q = Purchase.search params[:q]
  @purchase_scope = @q.result(:distinct => true)
  @purchases = @purchase_scope.includes(:basket => {:items => :product} ).paginate( :page => params[:page],:per_page => 20 ).to_a
end

#inventoryObject

receive the stuff (ie add to inventory)



32
33
34
35
36
# File 'app/controllers/purchases_controller.rb', line 32

def inventory
  items = @purchase.inventory!
  flash.notice = [t(:inventorized) ,items ,t(:items)].join(" ")
  redirect_to purchase_path(@purchase)
end

#newObject



38
39
40
41
42
43
44
# File 'app/controllers/purchases_controller.rb', line 38

def new
  today = Date.today
  basket = Basket.create!
  @purchase = Purchase.new :name => "#{I18n.t(:purchase)} #{I18n.l(today)}" , :basket => basket 
  @purchase.save!
  redirect_to edit_basket_path basket
end

#orderObject

order this from supplier



20
21
22
23
# File 'app/controllers/purchases_controller.rb', line 20

def order
  @purchase.order!
  redirect_to purchase_path(@purchase), :notice => t(:ordered)
end

#receiveObject

receive the stuff (ie add to inventory)



26
27
28
29
# File 'app/controllers/purchases_controller.rb', line 26

def receive
  items = @purchase.receive!
  redirect_to purchase_path(@purchase), :notice => [t(:received) ,items ,t(:items)].join(" ")
end

#showObject



15
16
17
# File 'app/controllers/purchases_controller.rb', line 15

def show
  gon.purchase_id = @purchase.id
end

#updateObject



59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/purchases_controller.rb', line 59

def update
  respond_to do |format|
    if @purchase.update_attributes(params_for_model)
      format.html { redirect_to purchase_path(@purchase), :notice => t(:update_success, :model => "purchase") }
      format.json { respond_with_bip(@purchase) }
    else
      format.html { render :action => :show }
      format.json { respond_with_bip(@purchase) }
    end
  end
end