reworked dividend
[smr.git] / gui / app / models / dividend.rb
blob5814ae18c94464a246bce021fa6a6d1a4220981a
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
7 # version.
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 class Dividend < ActiveRecord::Base
17         belongs_to :Stock, :foreign_key=>'id_stock'
18     has_many :Position, :foreign_key=>'id_stock', :primary_key=>'id_stock'
19     has_one :Position, :foreign_key=>'id', :primary_key=>'id_position'
20     has_one :Order, :foreign_key=>'id', :primary_key=>'id_order'
22     # data validations
23     validates :id_stock, :exdate, :paid, :id_position, :id_order, presence: true
24     validates :id_stock, :exdate, :paid, numericality: { greater_than_or_equal_to: 0 }
25     validates :id_position, :id_order, numericality: { greater_than_or_equal_to: 1 }
27     # Returns Time object from unix-timestamp in :exdate column.
28     def time_exdate
29         Time.at(exdate)
30     end
31 end