class OutgoingsController < ApplicationController before_filter :check_authentication # Creates a new Outgoing from the passed form parameters and redirects to the # Asset page. #-- # POST /outgoings def create asset = Asset.find(session[:asset_id]) outgoing = Outgoing.create outgoing.asset_id = asset.id outgoing.category_id = params[:outgoing][:category_id] outgoing.transaction_date = get_date( params[:outgoing]['transaction_date(1i)'], params[:outgoing]['transaction_date(2i)'], params[:outgoing]['transaction_date(3i)']) outgoing.amount = params[:outgoing][:amount] outgoing.balance = Balance.create(:asset_id => asset.id, :outgoing_id => outgoing.id, :transaction_date => outgoing.transaction_date, :amount => asset.balance - outgoing.amount) if outgoing.save redirect_to asset_path(session[:username], asset.id) else flash[:notice] = "Amount #{outgoing.errors.on(:amount)}" redirect_to :back end rescue ArgumentError => exception case exception.to_s when 'invalid date' flash[:notice] = 'Please select a real date.' else flash[:notice] = 'Please enter a numeric amount.' end outgoing.destroy redirect_to :back end # Finds the Outgoing with the specified ID, destroys it and redirects back to # the Asset page. #-- # DELETE /outgoings/1 def destroy outgoing = Outgoing.find(params[:id]) outgoing.destroy redirect_to :back end end