Class: Harvest::Invoice
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Harvest::Invoice
- Includes:
- Model
- Defined in:
- lib/harvest/invoice.rb
Overview
Fields
[+due_at+] when the invoice is due
[+due_at_human_format+] when the invoice is due in human representation (e.g., due upon receipt) overrides due_at
[+client_id+] (REQUIRED) the client id of the invoice
[+currency+] the invoice currency
[+issued_at+] when the invoice was issued
[+subject+] subject line for the invoice
[+notes+] notes on the invoice
[+number+] invoice number
[+kind+] (REQUIRED) the type of the invoice free_form|project|task|people|detailed
[+projects_to_invoice+] comma separated project ids to gather data from
[+import_hours+] import hours from project|task|people|detailed one of yes|no
[+import_expenses+] import expenses from project|task|people|detailed one of yes|no
[+period_start+] start of the invoice period
[+period_end+] end of the invoice period
[+expense_period_start+] start of the invoice expense period
[+expense_period_end+] end of the invoice expense period
[+csv_line_items+] csv formatted line items for the invoice kind,description,quantity,unit_price,amount,taxed,taxed2,project_id
[+created_at+] (READONLY) when the invoice was created
[+updated_at+] (READONLY) when the invoice was updated
[+id+] (READONLY) the id of the invoice
[+amount+] (READONLY) the amount of the invoice
[+due_amount+] (READONLY) the amount due on the invoice
[+created_by_id+] who created the invoice
[+purchase_order+] purchase order number/text
[+client_key+] unique client key
[+state+] (READONLY) state of the invoice
[+tax+] applied tax percentage
[+tax2+] applied tax 2 percentage
[+tax_amount+] amount to tax
[+tax_amount2+] amount to tax 2
[+discount_amount+] discount amount to apply to invoice
[+discount_type+] discount type
[+recurring_invoice_id+] the id of the original invoice
[+estimate_id+] id of the related estimate
[+retainer_id+] id of the related retainer
Instance Attribute Summary collapse
-
#line_items ⇒ Object
Returns the value of attribute line_items.
-
#update_line_items ⇒ Object
Returns the value of attribute update_line_items.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(*options) ⇒ Object
-
#initialize(args = {}, _ = nil) ⇒ Invoice
constructor
A new instance of Invoice.
Methods included from Model
Constructor Details
#initialize(args = {}, _ = nil) ⇒ Invoice
Returns a new instance of Invoice.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/harvest/invoice.rb', line 58 def initialize(args = {}, _ = nil) if args args = args.to_hash.stringify_keys self.line_items = args.delete("csv_line_items") self.line_items = args.delete("line_items") self.line_items = [] if self.line_items.nil? self.update_line_items = args.delete("update_line_items") end super end |
Instance Attribute Details
#line_items ⇒ Object
Returns the value of attribute line_items.
44 45 46 |
# File 'lib/harvest/invoice.rb', line 44 def line_items @line_items end |
#update_line_items ⇒ Object
Returns the value of attribute update_line_items.
45 46 47 |
# File 'lib/harvest/invoice.rb', line 45 def update_line_items @update_line_items end |
Class Method Details
.parse(json) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/harvest/invoice.rb', line 47 def self.parse(json) parsed = String === json ? JSON.parse(json) : json invoices = Array.wrap(parsed).map {|attrs| new(attrs["invoices"])} invoice = Array.wrap(parsed).map {|attrs| new(attrs["invoice"])} if invoices.first && invoices.first.length > 0 invoices else invoice end end |
Instance Method Details
#as_json(*options) ⇒ Object
80 81 82 83 84 |
# File 'lib/harvest/invoice.rb', line 80 def as_json(*) json = super(*) json[json_root]["csv_line_items"] = encode_csv(@line_items) if update_line_items json end |