Class: StocksController
- Inherits:
-
AuthorizedController
- Object
- AuthorizedController
- StocksController
- Defined in:
- app/controllers/stocks_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 |
# File 'app/controllers/stocks_controller.rb', line 29 def create @stock = Stock.new(params[:stock]) @stock.build_booking create! end |
#new ⇒ Object
Actions
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/stocks_controller.rb', line 7 def new # Defaults stock_params = { :state => 'available' } # Load and assign parent invoice if params[:invoice_id] invoice = Invoice.find(params[:invoice_id]) stock_params.merge!( :title => invoice.title, :amount => invoice.amount ) end # Paramameters stock_params.merge!(params[:stock] || {}) @stock = Stock.new(stock_params) end |
#write_downs ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/stocks_controller.rb', line 36 def write_downs # use current date if not specified otherwise if params[:by_value_period] @end_date = Date.parse(params[:by_value_period][:to]) @start_date = Date.parse(params[:by_value_period][:from]) else @end_date = Date.today @start_date = @end_date.to_time.advance(:years => -1, :days => 1).to_date end @date = @start_date..@end_date @stocks = Stock.all @stocks = @stocks.select{|stock| stock.balance(@start_date) != 0.0 or stock.balance(@end_date) != 0.0 } end |