class Sunnyside::PageData::InvoiceLine
InvoiceLine
does all the nitty-gritty parsing of an invoice line into the necessary fields the DB requres.
Attributes
Public Class Methods
# File lib/sunnyside/ledger/ledger.rb, line 118 def initialize(line, provider, post_date, client_name) @doc_date, @invoice, @client_id, @hours, @rate, @amount = line.split @post_date = post_date @client_name = client_name.strip @provider = provider end
Public Instance Methods
# 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
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.
# 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: post_date, provider_id: provider.id, client_name: client_name.strip) end end
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.
# File lib/sunnyside/ledger/ledger.rb, line 128 def amt amount.gsub(/,|\)'/, '') end
# File lib/sunnyside/ledger/ledger.rb, line 145 def client_missing? Client[client_id].nil? end
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.
# 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
# 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
# File lib/sunnyside/ledger/ledger.rb, line 177 def invoice_exist? !Invoice[invoice].nil? end
# File lib/sunnyside/ledger/ledger.rb, line 149 def new_provider? Client[client_id].provider_id != provider.id end
# File lib/sunnyside/ledger/ledger.rb, line 185 def prev_amt Invoice[invoice].amount end
# 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
# File lib/sunnyside/ledger/ledger.rb, line 181 def update_invoice Invoice[invoice].update(amount: amt.to_f) end