2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
16 require 'daemon_client'
19 # handles CRUD on Security records
22 # * this controller is called "Security" since the model is still Security. It
23 # will become "Security" when support for different types of paper is
24 # implemented (Bonds, Funds, Currency, ...).
25 # * until then we talk to the user about "Securities" already
27 class Objects::SecurityController < ObjectsController
30 # List all Security records for editing.
33 session[:objects_security_organization] = params[:id_organization] if params[:id_organization]
34 @id_organization = session[:objects_security_organization] || Smr::ID_UNIVERSE_ORGANIZATION
36 @securities, @total_pages = smr_paginate(
38 Security.where(:id_organization=>@id_organization).all.to_a.sort
40 @organizations = Organization.all.order(:name).to_a
41 @symbolextensions = SecuritySymbolextension.all.order(:extension).to_a
42 @symbolextensions.insert(0, SecuritySymbolextension.new(:extension=>'', :fullname=>'<None>', :id=>0))
43 @quotesources = SecurityQuotesource.all.order(:source).to_a
47 # defines empty Security to create() a new one
50 @security = Security.new
55 # retrieve Security for editing
56 # - NOTE: disabled @quote_retrieval_status because it hinders fluent
61 #daemon = begin Smr::DaemonClient.new rescue false end
63 @security = Security.find(params[:id])
64 @security_type = @security.get_type
65 #if @security.fetch_quote and daemon then
66 # daemon = Smr::DaemonClient.new
67 # @quote_retrieval_status = daemon.status_security(@security.id)
73 # handles creates and updates
77 if params[:security][:id_security_symbolextension].to_i == 0 then
78 params[:security][:id_security_symbolextension] = nil
81 if params[:security][:id].to_i > 0 then
82 s = Security.find(params[:security][:id])
83 s.update(security_params)
84 else s = Security.create(security_params) end
85 n << s.errors.full_messages.uniq
88 if params[:security_stock]
89 if params[:security_stock][:id].to_i > 0 then
90 st = SecurityStock.find(params[:security_stock][:id])
91 st.update(security_stock_params)
92 else st = SecurityStock.create(security_stock_params) end
93 n << st.errors.full_messages.uniq
96 if params[:security_bond]
97 if params[:security_bond][:id].to_i > 0 then
98 st = SecurityBond.find(params[:security_bond][:id])
99 st.update(security_bond_params)
100 else st = SecurityBond.create(security_bond_params) end
101 n << st.errors.full_messages.uniq
104 if params[:security_fund]
105 if params[:security_fund][:id].to_i > 0 then
106 st = SecurityFund.find(params[:security_fund][:id])
107 st.update(security_fund_params)
108 else st = SecurityFund.create(security_fund_params) end
109 n << st.errors.full_messages.uniq
112 redirect_to objects_security_index_path, :notice=>n.flatten.join(', ')
118 # internal helper defining parameters acceptable for Security create/update
120 params.require(:security).permit(
121 :symbol, :id_security_symbolextension, :id_security_quotesource,
122 :id_organization, :url, :brief, :description, :fetch_quote, :type,
123 :collateral_coverage_ratio
128 # internal helper defining parameters acceptable for Security Type model create/update
129 def security_stock_params
130 params.require(:security_stock).permit(
131 :id_security, :dividend, :time_dividend_exdate, :dividend_interval, :type, :comment
135 def security_bond_params
136 params.require(:security_bond).permit(
138 :type, :currency, :denomination, :is_subordinated, :is_callable, :is_stepup, :is_stepdown,
139 :coupon, :coupon_interval, :interest_method, :time_first_coupon, :time_last_coupon,
140 :time_maturity, :redemption_price, :redemption_installments, :redemption_interval,
145 def security_fund_params
146 params.require(:security_fund).permit(
148 :type, :currency, :tranche, :time_inception, :time_fiscalyearend, :investment_minimum, :is_synthetic,
149 :distribution, :time_distribution, :distribution_interval, :is_retaining_profits,
150 :issue_surcharge, :management_fee, :redemption_fee, :redemption_period,