Class: Cashboard::Invoice

Inherits:
Base show all
Defined in:
lib/cashboard/invoice.rb

Instance Attribute Summary

Attributes inherited from Base

#href, #id

Instance Method Summary collapse

Methods inherited from Base

authenticate, clear_authentication, create, #delete, #links, list, new_from_url, #to_xml, #update

Methods inherited from Struct

#initialize

Methods inherited from TypecastedOpenStruct

attr_typecast, element

Constructor Details

This class inherits a constructor from Cashboard::Struct

Instance Method Details

#get_import_xml_options(project_ids, start_date, end_date) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cashboard/invoice.rb', line 62

def get_import_xml_options(project_ids, start_date, end_date)
  xml_options = ''
  xml = Builder::XmlMarkup.new(:target => xml_options, :indent => 2)
  xml.instruct!
  xml.projects do
    project_ids.each {|pid| xml.id pid} if project_ids
  end
  xml.start_date start_date
  xml.end_date end_date
  
  return xml_options  
end

#import_uninvoiced_items(project_ids = {}, start_date = nil, end_date = nil) ⇒ Object

Imports uninvoiced items (time entries, expenses, flat fee tasks) that belong to the same client that this invoice was created for.

Either raises a Cashboard error (errors.rb) or returns a collection of Cashboard::InvoiceLineItem objects.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cashboard/invoice.rb', line 47

def import_uninvoiced_items(project_ids={}, start_date=nil, end_date=nil)
  xml_options = get_import_xml_options(project_ids, start_date, end_date)
  
  options = self.class.merge_options()
  options.merge!({:body => xml_options})
  response = self.class.put(self.links[:import_uninvoiced_items], options)
  
  self.class.check_status_code(response)
  
  collection = response.parsed_response[Cashboard::InvoiceLineItem.resource_name.singularize]      
  collection.map do |h| 
    Cashboard::InvoiceLineItem.new(h)
  end
end

#line_items(options = {}) ⇒ Object

Returns all associated LineItems



36
37
38
39
40
# File 'lib/cashboard/invoice.rb', line 36

def line_items(options={})
  self.class.get_collection(
    self.links[:line_items], Cashboard::InvoiceLineItem, options
  )
end