Sha256: 735fdbaac44af2965539fa9f3796d73d1ca7d55833e64259d42302c17debf3fe

Contents?: true

Size: 863 Bytes

Versions: 186

Compression:

Stored size: 863 Bytes

Contents

module Gemini::Extras::SettlementImport
  def import_validation(ids)
    validate_settlement_date(ids, 0)
  end

  def import_validation_allow_prior_month(ids)
    validate_settlement_date(ids, 1)
  end

private
  def validate_settlement_date(ids, month_interval)
    # Given a set of ids, make sure that settlement mm/yy are not more
    # than x months older than current date.
    bad = where("id IN (?) AND " +
                "date_trunc('month', current_date) - " +
                "INTERVAL '#{month_interval} month' > " +
                "format('%s-%s-01', settlement_yy, settlement_mm)::date",
                ids).limit(1)

    return if bad.empty?

    x = bad[0]

    raise "One or more records failed validation. " +
      "Settlement #{x.settlement_mm}/#{x.settlement_yy} is " +
      "#{month_interval + 1 } or more months in the past."
  end
end

Version data entries

186 entries across 186 versions & 1 rubygems

Version Path
marty-5.1.3 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-5.1.2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-5.1.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-5.1.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-3.1.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-3.0.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-4.0.0.rc2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-3.0.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.9.3 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.9.2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.9.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.8.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.7.3 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.7.2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.7.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.7.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.6.8 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.6.7 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.6.6 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-2.6.5 spec/dummy/app/models/gemini/extras/settlement_import.rb