2020-03-25 17:45:53 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# OfferDay provides a way for admins to extend the subscription of a member for free.
|
2020-03-25 10:16:47 +01:00
|
|
|
class OfferDay < ApplicationRecord
|
2016-03-23 18:39:41 +01:00
|
|
|
include NotifyWith::NotificationAttachedObject
|
|
|
|
|
2021-05-25 17:28:35 +02:00
|
|
|
has_many :invoice_items, as: :object, dependent: :destroy
|
2016-03-23 18:39:41 +01:00
|
|
|
belongs_to :subscription
|
2021-05-28 17:34:20 +02:00
|
|
|
|
|
|
|
# buying invoice
|
|
|
|
def original_invoice
|
|
|
|
invoice_items.select(:invoice_id)
|
|
|
|
.group(:invoice_id)
|
|
|
|
.map(&:invoice_id)
|
|
|
|
.map { |id| Invoice.find_by(id: id, type: nil) }
|
|
|
|
.first
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|