Class: ProviderReceiptTemplate
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProviderReceiptTemplate
- Defined in:
- app/models/provider_receipt_template.rb
Class Method Summary collapse
- .base ⇒ Object
- .entities ⇒ Object
- .for(payment) ⇒ Object
- .masks ⇒ Object
- .payment_fields ⇒ Object
- .provider_fields ⇒ Object
- .sample ⇒ Object
- .terminal_fields ⇒ Object
Instance Method Summary collapse
Class Method Details
.base ⇒ Object
5 6 7 |
# File 'app/models/provider_receipt_template.rb', line 5 def self.base ProviderReceiptTemplate.where(:system => true).first end |
.entities ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/models/provider_receipt_template.rb', line 17 def self.entities { :terminal => terminal_fields, :payment => payment_fields, :provider => provider_fields } end |
.for(payment) ⇒ Object
13 14 15 |
# File 'app/models/provider_receipt_template.rb', line 13 def self.for(payment) payment.provider.provider_receipt_template || base end |
.masks ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/models/provider_receipt_template.rb', line 57 def self.masks %w( payment_paid_amount payment_enrolled_amount payment_commission_amount payment_paid_at ) end |
.payment_fields ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/provider_receipt_template.rb', line 25 def self.payment_fields [ :id, :created_at, :paid_at, :foreign_id, :account, :fields, :paid_amount, :enrolled_amount, :commission_amount ] end |
.provider_fields ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/models/provider_receipt_template.rb', line 47 def self.provider_fields [ :title, :keyword, :juristic_name, :inn, :support_phone ] end |
.sample ⇒ Object
9 10 11 |
# File 'app/models/provider_receipt_template.rb', line 9 def self.sample ProviderReceiptTemplate.new :template => base.template end |
.terminal_fields ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/provider_receipt_template.rb', line 39 def self.terminal_fields [ :keyword, :address, :version ] end |
Instance Method Details
#compile(payment) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/provider_receipt_template.rb', line 70 def compile(payment) data = {} masks = self.class.masks self.class.entities.each do |entity, fields| fields.each do |field| model = (entity == :payment) ? payment : payment.send(entity) key = "#{entity}_#{field}" data[key] = masks.include?(key) ? "{{ #{key} }}" : model.send(field) end end Liquid::Template.parse(template).render data end |
#title ⇒ Object
66 67 68 |
# File 'app/models/provider_receipt_template.rb', line 66 def title providers.blank? ? "--" : providers.map{|x| x.title}.join(', ') end |