Class: Sunnyside::PageData::InvoiceLine
- Inherits:
-
Sunnyside::PageData
- Object
- Sunnyside::PageData
- Sunnyside::PageData::InvoiceLine
- 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
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#invoice ⇒ Object
Returns the value of attribute invoice.
-
#post_date ⇒ Object
Returns the value of attribute post_date.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#rate ⇒ Object
Returns the value of attribute rate.
Attributes inherited from Sunnyside::PageData
Instance Method Summary collapse
- #add_client ⇒ Object
-
#add_invoice ⇒ Object
rarely there may be an invoice line that contains an invoice number that already exists.
-
#amt ⇒ Object
Some invoice totals exceed $999.99, so the strings need to be parsed into a format, sans comma, that the DB will read correctly.
- #client_missing? ⇒ Boolean
-
#finalize ⇒ Object
Ocasionally, new clients will appear on the PDF doc.
- #fund_id ⇒ Object
-
#initialize(line, provider, post_date, client_name) ⇒ InvoiceLine
constructor
A new instance of InvoiceLine.
- #invoice_exist? ⇒ Boolean
- #new_provider? ⇒ Boolean
- #prev_amt ⇒ Object
- #update_client ⇒ Object
- #update_invoice ⇒ Object
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, 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 |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
117 118 119 |
# File 'lib/sunnyside/ledger/ledger.rb', line 117 def amount @amount end |
#client_id ⇒ Object
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_name ⇒ Object
Returns the value of attribute client_name.
117 118 119 |
# File 'lib/sunnyside/ledger/ledger.rb', line 117 def client_name @client_name end |
#hours ⇒ Object
Returns the value of attribute hours.
117 118 119 |
# File 'lib/sunnyside/ledger/ledger.rb', line 117 def hours @hours end |
#invoice ⇒ Object
Returns the value of attribute invoice.
117 118 119 |
# File 'lib/sunnyside/ledger/ledger.rb', line 117 def invoice @invoice end |
#post_date ⇒ Object
Returns the value of attribute post_date.
117 118 119 |
# File 'lib/sunnyside/ledger/ledger.rb', line 117 def post_date @post_date end |
#provider ⇒ Object
Returns the value of attribute provider.
117 118 119 |
# File 'lib/sunnyside/ledger/ledger.rb', line 117 def provider @provider end |
#rate ⇒ Object
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_client ⇒ Object
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_invoice ⇒ Object
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: post_date, provider_id: provider.id, client_name: client_name.strip) end end |
#amt ⇒ Object
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
145 146 147 |
# File 'lib/sunnyside/ledger/ledger.rb', line 145 def client_missing? Client[client_id].nil? end |
#finalize ⇒ Object
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_id ⇒ Object
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
177 178 179 |
# File 'lib/sunnyside/ledger/ledger.rb', line 177 def invoice_exist? !Invoice[invoice].nil? end |
#new_provider? ⇒ Boolean
149 150 151 |
# File 'lib/sunnyside/ledger/ledger.rb', line 149 def new_provider? Client[client_id].provider_id != provider.id end |
#prev_amt ⇒ Object
185 186 187 |
# File 'lib/sunnyside/ledger/ledger.rb', line 185 def prev_amt Invoice[invoice].amount end |
#update_client ⇒ Object
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_invoice ⇒ Object
181 182 183 |
# File 'lib/sunnyside/ledger/ledger.rb', line 181 def update_invoice Invoice[invoice].update(amount: amt.to_f) end |