Module: Models::ReceiptTransmission
- Extended by:
- ActiveSupport::Concern
- Included in:
- Receipt
- Defined in:
- app/concerns/models/receipt_transmission.rb
Overview
Customer-facing receipt email + transmission addressing: recipient
resolution, notification channels, and the contact points/first document
used to address communications.
Instance Method Summary collapse
-
#billing_address ⇒ Address?
Customer billing address used for emails/PDFs.
-
#determine_email ⇒ String
Recipient list for the receipt email.
-
#first_document ⇒ Invoice, ...
First Invoice or CreditMemo this receipt touches, used as the canonical "what does this receipt represent" object for emails and contact resolution.
-
#notification_emails ⇒ Array<String>
Email contact points the customer marked as receiving invoice notifications.
-
#primary_transmission_contact ⇒ ContactPoint?
Primary contact (per the first applied document) used when sending transmission/email events.
-
#send_email ⇒ Communication?
Send the customer-facing receipt email.
-
#transmission_contact_points ⇒ Array<ContactPoint>
All contact points associated with the first applied document, used to address transmission communications.
Instance Method Details
#billing_address ⇒ Address?
Returns customer billing address used for emails/PDFs.
41 42 43 |
# File 'app/concerns/models/receipt_transmission.rb', line 41 def billing_address customer&.billing_address end |
#determine_email ⇒ String
Recipient list for the receipt email. Online orders fan out to every
invoice notification address on the customer; back-office receipts
use the single email column captured at create time.
32 33 34 35 36 37 38 |
# File 'app/concerns/models/receipt_transmission.rb', line 32 def determine_email if (payment&.order&.order_reception_type == 'Online') && notification_emails.any? notification_emails.join(',') else email end end |
#first_document ⇒ Invoice, ...
First Invoice or CreditMemo this receipt touches, used as the
canonical "what does this receipt represent" object for emails and
contact resolution.
78 79 80 81 82 |
# File 'app/concerns/models/receipt_transmission.rb', line 78 def first_document return nil if receipt_details.empty? receipt_details.first.invoice || receipt_details.first.credit_memo end |
#notification_emails ⇒ Array<String>
Email contact points the customer marked as receiving invoice
notifications.
49 50 51 |
# File 'app/concerns/models/receipt_transmission.rb', line 49 def notification_emails customer.all_notification_channels.email.invoices.distinct.pluck(ContactPoint[:detail]) end |
#primary_transmission_contact ⇒ ContactPoint?
Primary contact (per the first applied document) used when sending
transmission/email events.
57 58 59 60 61 |
# File 'app/concerns/models/receipt_transmission.rb', line 57 def primary_transmission_contact return nil if first_document.nil? first_document.primary_transmission_contact end |
#send_email ⇒ Communication?
Send the customer-facing receipt email. Sender is the customer's
primary sales rep when present (BCC'd on the outgoing message);
otherwise the generic info inbox is used.
16 17 18 19 20 21 22 23 24 25 |
# File 'app/concerns/models/receipt_transmission.rb', line 16 def send_email sender = customer.try(:primary_sales_rep) CommunicationBuilder.new( resource: self, sender_party: sender, sender: (sender.nil? ? INFO_EMAIL : nil), emails: determine_email, bcc: sender&.email ).create end |
#transmission_contact_points ⇒ Array<ContactPoint>
All contact points associated with the first applied document, used
to address transmission communications.
67 68 69 70 71 |
# File 'app/concerns/models/receipt_transmission.rb', line 67 def transmission_contact_points return [] if first_document.nil? first_document.transmission_contact_points end |