Sha256: d936e5b59c1eda380e8a43bb6c26135939fbe94e1b13ec6f1253ddfea9564ad5
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
module Skr module Handlers class InvoiceFromTimeEntries def initialize(project_id, entry_ids, options = {}) @project = CustomerProject.find(project_id) @entry_ids = entry_ids @location = Location.default # should be set on project maybe? @sku_loc = @project.sku.sku_locs.find_by(location: @location) @options = options end def build_invoice invoice = Invoice.new( customer_project: @project, customer: @project.customer, po_num: @options['po_num'] || @project.po_num, notes: @options['notes'] ) @entry_ids.each do | entry_id | entry = TimeEntry.find(entry_id) invoice.lines.build( time_entry: entry, sku_loc: @sku_loc, price: @project.rates['hourly'], description: entry.description, qty: ((entry.end_at - entry.start_at) / 1.hour) ) end invoice end def self.handler lambda do wrap_reply do builder = InvoiceFromTimeEntries.new( data['customer_project_id'], data['time_entry_ids'], data ) invoice = builder.build_invoice std_api_reply :create, { invoice: invoice }, success: invoice.save end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stockor-0.3.0 | lib/skr/handlers/invoice_from_time_entries.rb |
stockor-0.2 | lib/skr/handlers/invoice_from_time_entries.rb |