Skip to Content Skip to Search
Methods
A
B
C
D
N
R
S
T

Attributes

[R] coupon
[R] currency
[R] customer_id
[R] description
[R] id
[R] items
[R] status

Class Public methods

new(data, policy)

# File app/models/billing/invoice.rb, line 5
def initialize(data, policy)
  data = policy.new(data).data
  @id = data.id
  @customer_id = data.customer_id
  @timestamp = data.timestamp
  @status = data.status
  @description = data.description
  @currency = data.currency
  @total = data.total
  @amount_due = data.amount_due
  @amount_refunded = data.amount_refunded
  @applied_balance = data.applied_balance

  @timestamp_start = data.try(:timestamp_start)
  @timestamp_end = data.try(:timestamp_end)
  @tax = data.try(:tax)
  @tax_percent = data.try(:tax_percent)

  @coupon = generate_coupon(data.coupon)
  @items = generate_invoice_items(data.items)
end

Instance Public methods

amount_due()

# File app/models/billing/invoice.rb, line 67
def amount_due
  Service::Money.new(@amount_due, @currency).format
end

amount_refunded()

# File app/models/billing/invoice.rb, line 48
def amount_refunded
  @amount_refunded || 0
end

applied_balance()

# File app/models/billing/invoice.rb, line 60
def applied_balance
  if @applied_balance && @applied_balance < 0
    Service::Money.new(@applied_balance,
      @currency).format
  end
end

billing_period()

# File app/models/billing/invoice.rb, line 36
def billing_period
  if @timestamp_start && @timestamp_end
    start = format_timestamp @timestamp_start
    stop = format_timestamp @timestamp_end
    I18n.t("time.ranges.period", from: start, upto: stop)
  end
end

coupon_description()

# File app/models/billing/invoice.rb, line 89
def coupon_description
  if coupon.present?
    coupon.description
  end
end

date()

# File app/models/billing/invoice.rb, line 27
def date
  format_timestamp @timestamp
end

date_short()

# File app/models/billing/invoice.rb, line 31
def date_short
  time = Time.zone.at @timestamp
  I18n.l(time, format: :short_ordinal)
end

refund?()

# File app/models/billing/invoice.rb, line 71
def refund?
  @amount_refunded && @amount_refunded > 0
end

refund_amount()

# File app/models/billing/invoice.rb, line 75
def refund_amount
  Service::Money.new(@amount_refunded, @currency).format
end

starting_balance()

# File app/models/billing/invoice.rb, line 56
def starting_balance
  Service::Money.new(@starting_balance, @currency).format if @starting_balance
end

tax()

# File app/models/billing/invoice.rb, line 44
def tax
  @tax || 0
end

tax_line()

# File app/models/billing/invoice.rb, line 79
def tax_line
  if @items.last.plan_id
    plan = DB::Plan.find_by({payment_gateway_id: @items.last.plan_id})
    if plan && @tax_percent.to_i > 0 && @tax.to_i > 0
      "#{plan.tax_description} #{@tax_percent}% : #{Service::Money.new(@tax,
        @currency).format}"
    end
  end
end

total()

# File app/models/billing/invoice.rb, line 52
def total
  Service::Money.new(@total, @currency).format
end