Sha256: e7c6248fef7cdfb87b303286c8fb8ca3aaf3b97a0c18b760bfe01602242ce4da

Contents?: true

Size: 935 Bytes

Versions: 26

Compression:

Stored size: 935 Bytes

Contents

class Dorsale::BillingMachine::Quotation::ToInvoice < ::Dorsale::Service
  attr_accessor :quotation, :invoice

  def initialize(quotation)
    @quotation = quotation
  end

  def call
    @invoice = Dorsale::BillingMachine::Invoice.new

    quotation.attributes.each do |k, v|
      next if k.to_s == "id"
      next if k.to_s.match /index|tracking|state/
      next if k.to_s.end_with?("_at")

      if invoice.respond_to?("#{k}=")
        invoice.public_send("#{k}=", v)
      end
    end

    quotation.lines.each do |quotation_line|
      invoice_line = invoice.lines.new

      quotation_line.attributes.each do |k, v|
        next if k.to_s == "id"
        next if k.to_s.match /index|tracking|state/
        next if k.to_s.end_with?("_at")

        if invoice_line.respond_to?("#{k}=")
          invoice_line.public_send("#{k}=", v)
        end
      end
    end

    invoice.date = Time.zone.now.to_date

    invoice
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dorsale-3.8.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.8.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.8 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.7 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.6 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.5 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.4 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.2 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.7.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.6.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.6.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.5.2 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.5.1 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.5.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.4.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.3.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.2.0 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.1.7 app/services/dorsale/billing_machine/quotation/to_invoice.rb
dorsale-3.1.6 app/services/dorsale/billing_machine/quotation/to_invoice.rb