Method: Osm::Invoice.get_for_section
- Defined in:
- lib/osm/invoice.rb
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Invoice>
Get invoices for a section
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/osm/invoice.rb', line 50 def self.get_for_section(api, section, ={}) require_ability_to(api, :read, :finance, section, ) section_id = section.to_i cache_key = ['invoice_ids', section_id] invoices = nil if ![:no_cache] && cache_exist?(api, cache_key) ids = cache_read(api, cache_key) invoices = get_from_ids(api, ids, 'invoice', section, , :get_for_section) end if invoices.nil? data = api.perform_query("finances.php?action=getInvoices§ionid=#{section_id}&showArchived=true") invoices = Array.new ids = Array.new unless data['items'].nil? data['items'].map { |i| i['invoiceid'].to_i }.each do |invoice_id| invoice_data = api.perform_query("finances.php?action=getInvoice§ionid=#{section_id}&invoiceid=#{invoice_id}") invoice = self.new_invoice_from_data(invoice_data) invoices.push invoice ids.push invoice.id cache_write(api, ['invoice', invoice.id], invoice) end end cache_write(api, cache_key, ids) end return invoices if [:include_archived] return invoices.reject do |invoice| invoice.archived? end end |