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-14.3.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-14.0.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-13.0.2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-11.0.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-10.0.3 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-10.0.2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-10.0.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-9.5.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-9.5.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-9.3.3 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-9.3.2 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-9.3.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-8.5.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-8.4.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-8.3.1 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-8.2.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-8.0.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-6.1.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-5.2.0 spec/dummy/app/models/gemini/extras/settlement_import.rb
marty-5.1.4 spec/dummy/app/models/gemini/extras/settlement_import.rb