Class: Sunnyside::AuthReport

Inherits:
Object
  • Object
show all
Defined in:
lib/sunnyside/expiring_auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, auth) ⇒ AuthReport

Returns a new instance of AuthReport.



79
80
81
82
83
# File 'lib/sunnyside/expiring_auth.rb', line 79

def initialize(client, auth)
  @auth   = auth
  @client_auth            = client
  @visits                 = Visit.where(member_id: client.get(:client_number)).all.select { |visit| auth.end_date < visit.dos }
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



77
78
79
# File 'lib/sunnyside/expiring_auth.rb', line 77

def auth
  @auth
end

#client_authObject (readonly)

Returns the value of attribute client_auth.



77
78
79
# File 'lib/sunnyside/expiring_auth.rb', line 77

def client_auth
  @client_auth
end

#invoicesObject (readonly)

Returns the value of attribute invoices.



77
78
79
# File 'lib/sunnyside/expiring_auth.rb', line 77

def invoices
  @invoices
end

#visitsObject (readonly)

Returns the value of attribute visits.



77
78
79
# File 'lib/sunnyside/expiring_auth.rb', line 77

def visits
  @visits
end

Instance Method Details

#create_csvObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sunnyside/expiring_auth.rb', line 85

def create_csv
  if expired?
    CSV.open('auth_report', 'a+') { |row| row << ['EXPIRED', auth.client, auth.provider, auth.start_date, auth.end_date, auth.auth] }
    if visits.count > 0
      # puts visits
      visits.each { |visit| CSV.open('auth_report', 'a+') { |row| row << [''       , visit.dos, visit.service_code, visit.units, visit.amount] } }
    end
  else
    CSV.open('auth_report', 'a+') { |row| row << ['PENDING', auth.client, auth.provider, auth.start_date, auth.end_date, auth.auth] }
  end
end

#expired?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/sunnyside/expiring_auth.rb', line 97

def expired?
  auth.end_date < Date.today
end