class Sunnyside::PageData::InvoiceLine

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

Attributes

amount[RW]
client_id[RW]
client_name[RW]
hours[RW]
invoice[RW]
post_date[RW]
provider[RW]
rate[RW]

Public Class Methods

new(line, provider, post_date, client_name) click to toggle source
# 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

add_client() click to toggle source
# 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_invoice() click to toggle source

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
amt() click to toggle source

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
client_missing?() click to toggle source
# File lib/sunnyside/ledger/ledger.rb, line 145
def client_missing?
  Client[client_id].nil?
end
finalize() click to toggle source

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
fund_id() click to toggle source
# 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?() click to toggle source
# File lib/sunnyside/ledger/ledger.rb, line 177
def invoice_exist?
  !Invoice[invoice].nil?
end
new_provider?() click to toggle source
# File lib/sunnyside/ledger/ledger.rb, line 149
def new_provider?
  Client[client_id].provider_id != provider.id
end
prev_amt() click to toggle source
# File lib/sunnyside/ledger/ledger.rb, line 185
def prev_amt
  Invoice[invoice].amount
end
update_client() click to toggle source
# 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_invoice() click to toggle source
# File lib/sunnyside/ledger/ledger.rb, line 181
def update_invoice
  Invoice[invoice].update(amount: amt.to_f)
end