Class: Jbr::Invoice
Overview
A bill a Jobber user issued for finished work.
Direct Known Subclasses
Constant Summary collapse
- FIND =
The query that reads one invoice, its total, its date and the job it bills.
<<~GRAPHQL query($id: EncodedId!) { invoice(id: $id) { id total invoiceStatus issuedDate jobs { nodes { id completedAt } } } } GRAPHQL
Instance Attribute Summary collapse
-
#job_id ⇒ String?
readonly
The ID of the job billed, and the amount as Jobber writes it.
-
#total ⇒ String?
readonly
The ID of the job billed, and the amount as Jobber writes it.
Attributes inherited from Resource
Instance Method Summary collapse
-
#completed_at ⇒ Time
The job completed time.
-
#find(id) ⇒ Invoice?
Itself, or nil when the invoice is missing or still a draft.
-
#issued_at ⇒ Date
The invoice issued time.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Jbr::Resource
Instance Attribute Details
#job_id ⇒ String? (readonly)
Returns the ID of the job billed, and the amount as Jobber writes it.
13 14 15 |
# File 'lib/jbr/invoice.rb', line 13 def job_id @job_id end |
#total ⇒ String? (readonly)
Returns the ID of the job billed, and the amount as Jobber writes it.
13 14 15 |
# File 'lib/jbr/invoice.rb', line 13 def total @total end |
Instance Method Details
#completed_at ⇒ Time
Returns the job completed time.
39 40 41 |
# File 'lib/jbr/invoice.rb', line 39 def completed_at Time.iso8601(@completed_at) if @completed_at end |
#find(id) ⇒ Invoice?
Returns itself, or nil when the invoice is missing or still a draft.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jbr/invoice.rb', line 17 def find(id) output = @oauth.query FIND, variables: { id: id } return unless invoice = output['invoice'] return if invoice['invoiceStatus'].eql? 'draft' @id = invoice['id'] @total = invoice['total'] @issued_at = invoice['issuedDate'] job = invoice.dig('jobs', 'nodes', 0) || {} @job_id = job['id'] @completed_at = job['completedAt'] self end |
#issued_at ⇒ Date
Returns the invoice issued time.
34 35 36 |
# File 'lib/jbr/invoice.rb', line 34 def issued_at Time.iso8601(@issued_at) if @issued_at end |