Class: Sunnyside::PageData::InvoiceLine

Inherits:
Sunnyside::PageData show all
Defined in:
lib/sunnyside/ledger/ledger.rb

Overview

InvoiceLine does all the nitty-gritty parsing of an invoice line into the necessary fields the DB requres.

Instance Attribute Summary collapse

Attributes inherited from Sunnyside::PageData

#invoice_data, #page_data

Instance Method Summary collapse

Methods inherited from Sunnyside::PageData

#formatted_provider, #invoice_lines, #provider_missing?

Constructor Details

#initialize(line, provider, post_date, client_name) ⇒ InvoiceLine

Returns a new instance of InvoiceLine.



118
119
120
121
122
123
# File 'lib/sunnyside/ledger/ledger.rb', line 118

def initialize(line, provider, , client_name)
  @doc_date, @invoice, @client_id, @hours, @rate, @amount = line.split
  @post_date                                              = 
  @client_name                                            = client_name.strip
  @provider                                               = provider
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def amount
  @amount
end

#client_idObject

Returns the value of attribute client_id.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def client_id
  @client_id
end

#client_nameObject

Returns the value of attribute client_name.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def client_name
  @client_name
end

#hoursObject

Returns the value of attribute hours.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def hours
  @hours
end

#invoiceObject

Returns the value of attribute invoice.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def invoice
  @invoice
end

#post_dateObject

Returns the value of attribute post_date.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def 
  @post_date
end

#providerObject

Returns the value of attribute provider.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def provider
  @provider
end

#rateObject

Returns the value of attribute rate.



117
118
119
# File 'lib/sunnyside/ledger/ledger.rb', line 117

def rate
  @rate
end

Instance Method Details

#add_clientObject



162
163
164
# File 'lib/sunnyside/ledger/ledger.rb', line 162

def add_client
  Client.insert(client_number: client_id, client_name: client_name.strip, fund_id: fund_id, provider_id: provider.id, prov_type: provider.prov_type)
end

#add_invoiceObject

rarely there may be an invoice line that contains an invoice number that already exists. This method accounts for it, by merely updating the amount. There has only been two instances of this happening and both occurred in 2011.



169
170
171
172
173
174
175
# File 'lib/sunnyside/ledger/ledger.rb', line 169

def add_invoice
  if invoice_exist?
    update_invoice
  else
    Invoice.insert(invoice_number: invoice, rate: rate, hours: hours, amount: amt, client_id: client_id, post_date: , provider_id: provider.id, client_name: client_name.strip)
  end
end

#amtObject

Some invoice totals exceed $999.99, so the strings need to be parsed into a format, sans comma, that the DB will read correctly. Otherwise, the DB will read 1,203.93 as 1.0.



128
129
130
# File 'lib/sunnyside/ledger/ledger.rb', line 128

def amt
  amount.gsub(/,|\)'/, '')
end

#client_missing?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/sunnyside/ledger/ledger.rb', line 145

def client_missing?
  Client[client_id].nil?
end

#finalizeObject

Ocasionally, new clients will appear on the PDF doc. If the DB does not find a client with the client_id, then it executes a method wherein new client gets saved into the DB with a new FUND EZ ID. It must do this before saving the invoice information.



135
136
137
138
139
140
141
142
143
# File 'lib/sunnyside/ledger/ledger.rb', line 135

def finalize
  if !client_missing? 
    update_client if new_provider?
    add_invoice
  else 
    add_client
    add_invoice
  end
end

#fund_idObject



157
158
159
160
# File 'lib/sunnyside/ledger/ledger.rb', line 157

def fund_id
  print "Enter in the FUND EZ ID for this client: #{client_name} of #{provider.name}: "
  return gets.chomp
end

#invoice_exist?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/sunnyside/ledger/ledger.rb', line 177

def invoice_exist?
  !Invoice[invoice].nil?
end

#new_provider?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/sunnyside/ledger/ledger.rb', line 149

def new_provider?
  Client[client_id].provider_id != provider.id
end

#prev_amtObject



185
186
187
# File 'lib/sunnyside/ledger/ledger.rb', line 185

def prev_amt
  Invoice[invoice].amount
end

#update_clientObject



153
154
155
# File 'lib/sunnyside/ledger/ledger.rb', line 153

def update_client
  Client[client_id].update(provider_id: provider.id, prov_type: provider.prov_type)
end

#update_invoiceObject



181
182
183
# File 'lib/sunnyside/ledger/ledger.rb', line 181

def update_invoice
  Invoice[invoice].update(amount: amt.to_f)
end