Class: Inventorymaster::TransactionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /transactions



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 34

def create
  @transaction = Transaction.new(transaction_params)
  @product = Product.find(@transaction.product_id)

  if @transaction.kind =="Entrada" && @product.ammount!= nil
    @product.ammount += @transaction.ammount
  elsif @transaction.kind == "Saida" && @product.ammount!= nil
    @product.ammount -= @transaction.ammount
  elsif @transaction.kind =="Entrada" && @product.ammount == nil
    @product.ammount = @transaction.ammount
  elsif @transaction.kind == "Saida" && @product.ammount== nil
    #@product.ammount =0
    @product.ammount - @transaction.ammount
  else
  end

  if @transaction.save && @product.save
    redirect_to @product, notice: 'Transaction was successfully created.'
  else
    render :new
  end
end

#destroyObject

DELETE /transactions/1



70
71
72
73
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 70

def destroy
  @transaction.destroy
  redirect_to transactions_url, notice: 'Transaction was successfully destroyed.'
end

#editObject

GET /transactions/1/edit



27
28
29
30
31
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 27

def edit
   @products = Product.all
  @locations = Location.all
  @transactiontypes = TransactionType.all
end

#indexObject

GET /transactions



8
9
10
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 8

def index
  @transactions = Transaction.all
end

#newObject

GET /transactions/new



17
18
19
20
21
22
23
24
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 17

def new
  @transaction = Transaction.new
  @products = Product.all
  @locations = Location.all
  @transactiontypes = TransactionType.all
  @transaction.product_id = params[:product_id]
  @transaction.kind = params[:kind]
end

#showObject

GET /transactions/1



13
14
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 13

def show
end

#updateObject

PATCH/PUT /transactions/1



58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 58

def update
   @products = Product.all
  @locations = Location.all
  @transactiontypes = TransactionType.all
  if @transaction.update(transaction_params)
    redirect_to @transaction, notice: 'Transaction was successfully updated.'
  else
    render :edit
  end
end