app/models/recurring_invoice.rb
# Returns a list of (not-yet-saved) pending invoices for this instance.
Returns a list of (not-yet-saved) pending invoices for this instance.
Returns a list of ( not - yet - saved ) pending invoices for this instance .
def build_pending_invoices
    next_occurrences.map do |issue_date|
      invoice = self.becomes(Invoice).dup
      invoice.period = nil
      invoice.period_type = nil
      invoice.starting_date = nil
      invoice.finishing_date = nil
      invoice.max_occurrences = nil
      self.items.each do |item|
        nitem = Item.new(item.attributes)
        nitem.id = nil
        item.taxes.each do |tax|
          nitem.taxes << tax
        end
        invoice.items << nitem
      end
      invoice.recurring_invoice = self
      invoice.issue_date = issue_date
      invoice.due_date = invoice.issue_date + days_to_due.days if days_to_due
      invoice.sent_by_email = false
      invoice.meta_attributes = meta_attributes
      invoice.items.each do |item|
        item.description.sub! "$(issue_date)", invoice.issue_date.strftime('%Y-%m-%d')
        item.description.sub! "$(issue_date - period)", (invoice.issue_date - period.send(period_type)).strftime('%Y-%m-%d')
        item.description.sub! "$(issue_date + period)", (invoice.issue_date + period.send(period_type)).strftime('%Y-%m-%d')
      end
      invoice
    end
  end
def build_pending_invoices next_occurrences . map do | issue_date | invoice = self . becomes ( Invoice ) . dup invoice . period = nil invoice . period_type = nil invoice . starting_date = nil invoice . finishing_date = nil invoice . max_occurrences = nil self . items . each do | item | nitem = Item . new ( item . attributes ) nitem . id = nil item . taxes . each do | tax | nitem . taxes << tax end invoice . items << nitem end invoice . recurring_invoice = self invoice . issue_date = issue_date invoice . due_date = invoice . issue_date + days_to_due . days if days_to_due invoice . sent_by_email = false invoice . meta_attributes = meta_attributes invoice . items . each do | item | item . description . sub! "$(issue_date)" , invoice . issue_date . strftime ( '%Y-%m-%d' ) item . description . sub! "$(issue_date - period)" , ( invoice . issue_date - period . send ( period_type ) ) . strftime ( '%Y-%m-%d' ) item . description . sub! "$(issue_date + period)" , ( invoice . issue_date + period . send ( period_type ) ) . strftime ( '%Y-%m-%d' ) end invoice end end
Returns a list of (not-yet-saved) pending invoices for this instance.
Returns a list of ( not - yet - saved ) pending invoices for this instance .