Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Ruby by Ricardo ( 13 years ago )
class InterestCalculator
  def self.calculate(*attributes)
    new(*attributes).calculate
  end

  def initialize(resource)
    @resource = resource
  end

  def calculate
    @resource.issqn_value * @resource.prefecture_interest * workdays
  end

  private

  def workdays
    WorkdayCalculator.new(@resource.prefecture_default_due_date, Date.today).workdays_count
  end
end

class Invoice < ActiveRecord::Base
  def tax_total
    issqn_value + rate_expedient + fine + interest
  end

  def fine
    return super if super.present?

    if prefecture.default_due_date < Date.today
      prefecture.delay_value
    else
      zero
    end
  end

  def interest
    return super if super.present?

    if prefecture.default_due_date < Date.today
      InterestCalculator.calculate(self)
    else
      zero
    end
  end

  private

  def rate_expedient
    prefecture.rate_expedient
  end

  def zero
    BigDecimal.new("0")
  end
end

 

Revise this Paste

Your Name: Code Language: