Class: Inventorymaster::TransactionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Inventorymaster::TransactionsController
- Defined in:
- app/controllers/inventorymaster/transactions_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /transactions.
-
#destroy ⇒ Object
DELETE /transactions/1.
-
#edit ⇒ Object
GET /transactions/1/edit.
-
#index ⇒ Object
GET /transactions.
-
#new ⇒ Object
GET /transactions/new.
-
#show ⇒ Object
GET /transactions/1.
-
#update ⇒ Object
PATCH/PUT /transactions/1.
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
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 |
#index ⇒ Object
GET /transactions
8 9 10 |
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 8 def index @transactions = Transaction.all end |
#new ⇒ Object
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 |
#show ⇒ Object
GET /transactions/1
13 14 |
# File 'app/controllers/inventorymaster/transactions_controller.rb', line 13 def show end |
#update ⇒ Object
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 |