Sha256: 6c3d60e95fde0b2a085893169ec89df55df814bf1c351f9a16f4aa8cec7ce0c0

Contents?: true

Size: 946 Bytes

Versions: 2

Compression:

Stored size: 946 Bytes

Contents

module ExpenseGun
  class ExpenseLine < ActiveRecord::Base
    belongs_to :expense
    belongs_to :category
    
    def initialize(h = {})
      super({company_part: 100}.merge(h))
    end
    
    validates :expense,         presence: true
    validates :name,            presence: true
    validates :date,            presence: true
    validates :category,        presence: true
    validates :total_all_taxes, presence: true, numericality: {greater_than_or_equal_to: 1.0}
    validates :vat,             presence: true, numericality: {greater_than_or_equal_to: 1.0}
    validates :company_part,    presence: true, numericality: {greater_than_or_equal_to: 1.0, less_than_or_equal_to: 100.0}
    
    # simple_form
    validates :category_id, presence: true
    
    def employee_payback
      (total_all_taxes * company_part / 100)
    end
    
    def total_vat_deductible
      category.vat_deductible == true ? vat : 0.0
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
expense_gun-1.0.2 app/models/expense_gun/expense_line.rb
expense_gun-1.0.1 app/models/expense_gun/expense_line.rb