Module: Models::AccountingDocumentTransmittable
- Extended by:
- ActiveSupport::Concern
- Included in:
- CreditMemo, Invoice, StatementOfAccount
- Defined in:
- app/concerns/models/accounting_document_transmittable.rb
Instance Method Summary collapse
- #can_be_transmitted? ⇒ Boolean
-
#fallback_notification_channel_type ⇒ Object
if credit_memos or statement_of_accounts notification channel is not set up, fall back to the invoices notification channel.
- #notification_channel_sort_order ⇒ Object
- #notification_channel_types ⇒ Object
- #notification_channels ⇒ Object
- #own_notification_channel_type ⇒ Object
- #post_communication_exception_hook(_params = {}) ⇒ Object
- #post_communication_sent_hook(_params = {}) ⇒ Object
- #primary_transmission_contact ⇒ Object
- #primary_transmission_contact_point_id ⇒ Object
- #transmission_contact_points ⇒ Object
Instance Method Details
#can_be_transmitted? ⇒ Boolean
34 35 36 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 34 def can_be_transmitted? transmission_contact_points.any? end |
#fallback_notification_channel_type ⇒ Object
if credit_memos or statement_of_accounts notification channel is not set up, fall back to the invoices notification channel
43 44 45 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 43 def fallback_notification_channel_type NotificationChannel::INVOICES end |
#notification_channel_sort_order ⇒ Object
51 52 53 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 51 def notification_channel_sort_order "CASE notification_type when '#{own_notification_channel_type}' then 1 when '#{fallback_notification_channel_type}' then 2 else 3 end, id" end |
#notification_channel_types ⇒ Object
47 48 49 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 47 def notification_channel_types [own_notification_channel_type, fallback_notification_channel_type] end |
#notification_channels ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 55 def notification_channels # notification_channel.notification_type could be: invoices, credit_memos, statement_of_accounts # if the customer has matching notification channels set up, use them # next try the billing customer for matching notification channels # next try the customer for the fallback notification channels # next try the billing customer for fallback notification channels # else return empty array if customer.notification_channels.where(notification_type: own_notification_channel_type).any? customer.notification_channels.where(notification_type: own_notification_channel_type) elsif billing_customer && billing_customer.notification_channels.fallback_enabled.where(notification_type: own_notification_channel_type).any? billing_customer.notification_channels.fallback_enabled.where(notification_type: own_notification_channel_type) elsif customer.notification_channels.where(notification_type: fallback_notification_channel_type).any? customer.notification_channels.where(notification_type: fallback_notification_channel_type) elsif billing_customer && billing_customer.notification_channels.fallback_enabled.where(notification_type: fallback_notification_channel_type).any? billing_customer.notification_channels.fallback_enabled.where(notification_type: fallback_notification_channel_type) else [] end end |
#own_notification_channel_type ⇒ Object
38 39 40 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 38 def own_notification_channel_type self.class.to_s.underscore.pluralize end |
#post_communication_exception_hook(_params = {}) ⇒ Object
100 101 102 103 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 100 def post_communication_exception_hook(_params = {}) # Mark document as transmitted after communication is sent transmission_exception end |
#post_communication_sent_hook(_params = {}) ⇒ Object
95 96 97 98 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 95 def post_communication_sent_hook(_params = {}) # Mark document as transmitted after communication is sent transmit end |
#primary_transmission_contact ⇒ Object
91 92 93 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 91 def primary_transmission_contact transmission_contact_points.first&.party end |
#primary_transmission_contact_point_id ⇒ Object
87 88 89 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 87 def primary_transmission_contact_point_id transmission_contact_points.first&.id end |
#transmission_contact_points ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/concerns/models/accounting_document_transmittable.rb', line 75 def transmission_contact_points if notification_channels.present? # if the customer has an invoice notification channel set up, use that ContactPoint.where(id: notification_channels.collect(&:contact_point_id).compact).transmittable elsif billing_customer&.profile && (billing_customer.profile.homeowner? || billing_customer.profile.direct_pro?) # it's a homeowner, so just use their preferred contact point customer.contact_points.transmittable.any? ? [customer.contact_points.transmittable.first] : [] else [] end end |