Class: Billing::Bill
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Billing::Bill
- Defined in:
- app/models/billing/bill.rb
Instance Attribute Summary collapse
-
#perform_fiscalize ⇒ Object
Returns the value of attribute perform_fiscalize.
-
#perform_print ⇒ Object
Returns the value of attribute perform_print.
Instance Method Summary collapse
- #build_typed_payment(attributes = {}) ⇒ Object
- #charge(*args) ⇒ Object
- #find_operator_mapping_for(fiscal_driver) ⇒ Object
- #fiscalizable? ⇒ Boolean
- #fiscalize(detailed = false) ⇒ Object
- #global_modifier_value ⇒ Object
- #has_payments? ⇒ Boolean
- #modifier_items ⇒ Object
- #modify(*args) ⇒ Object
- #origins ⇒ Object
- #paid? ⇒ Boolean
- #pay(*args) ⇒ Object
- #payment_types ⇒ Object
- #printable? ⇒ Boolean
- #tax_groups ⇒ Object
Instance Attribute Details
#perform_fiscalize ⇒ Object
Returns the value of attribute perform_fiscalize.
6 7 8 |
# File 'app/models/billing/bill.rb', line 6 def perform_fiscalize @perform_fiscalize end |
#perform_print ⇒ Object
Returns the value of attribute perform_print.
6 7 8 |
# File 'app/models/billing/bill.rb', line 6 def perform_print @perform_print end |
Instance Method Details
#build_typed_payment(attributes = {}) ⇒ Object
91 92 93 94 |
# File 'app/models/billing/bill.rb', line 91 def build_typed_payment(attributes = {}) payment_origin = attributes[:origin] || origins.find_by_id(attributes[:origin_id]) payments.new(attributes.merge(type: (payment_origin || origin).try(:payment_model) || 'Billing::PaymentWithType')) end |
#charge(*args) ⇒ Object
55 56 57 |
# File 'app/models/billing/bill.rb', line 55 def charge(*args) charges.wild(*args) end |
#find_operator_mapping_for(fiscal_driver) ⇒ Object
119 120 121 122 |
# File 'app/models/billing/bill.rb', line 119 def find_operator_mapping_for(fiscal_driver) # get operator, who close/pay the bill? #operator.operator_fiscal_driver_mapping.find_by(extface_driver_id: fiscal_driver.id) if fiscal_driver.fiscal? end |
#fiscalizable? ⇒ Boolean
124 125 126 |
# File 'app/models/billing/bill.rb', line 124 def fiscalizable? self.finalized_at.present? && payments.select(&:fiscal?).any? && origin.try(:fiscal_device) && balance.zero? end |
#fiscalize(detailed = false) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/billing/bill.rb', line 96 def fiscalize(detailed = false) #TODO create resque job #self.extface_job = origin.fiscal_device.driver.fiscalize(self, detailed) if fiscalizable? && origin.try(:fiscal_device) #self.extface_job if save if defined?(Extface) && fiscalizable? && device = origin.try(:fiscal_device) #self.extface_job = origin.fiscal_device.driver.fiscalize(self) if fiscalizable? && origin.try(:fiscal_device) self.extface_job = device.jobs.new self.perform_fiscalize = true self.extface_job if save end end |
#global_modifier_value ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'app/models/billing/bill.rb', line 108 def global_modifier_value global_modifiers = modifiers.select{ |m| m.charge.nil? } if global_modifiers.any? gvalue = Money.new(0) global_modifiers.each do |global_modifier| gvalue += global_modifier.percent_ratio.nil? ? global_modifier.fixed_value : (charges.to_a.sum(0.to_money, &:value).to_money * global_modifier.percent_ratio) end return gvalue end end |
#has_payments? ⇒ Boolean
83 84 85 |
# File 'app/models/billing/bill.rb', line 83 def has_payments? payments.any? end |
#modifier_items ⇒ Object
67 68 69 |
# File 'app/models/billing/bill.rb', line 67 def modifier_items calculate_modifiers end |
#modify(*args) ⇒ Object
59 60 61 |
# File 'app/models/billing/bill.rb', line 59 def modify(*args) modifiers.wild(*args) end |
#origins ⇒ Object
75 76 77 |
# File 'app/models/billing/bill.rb', line 75 def origins billable.try(:billing_origins) || billable.try(:origins) #|| Billing::Origin.all #FIXME end |
#paid? ⇒ Boolean
87 88 89 |
# File 'app/models/billing/bill.rb', line 87 def paid? has_payments? && balance.zero? end |
#pay(*args) ⇒ Object
63 64 65 |
# File 'app/models/billing/bill.rb', line 63 def pay(*args) payments.wild(*args) end |
#payment_types ⇒ Object
71 72 73 |
# File 'app/models/billing/bill.rb', line 71 def payment_types billable.try(:billing_payment_types) || billable.try(:payment_types) #|| Billing::PaymentType.all #FIXME end |
#printable? ⇒ Boolean
128 129 130 |
# File 'app/models/billing/bill.rb', line 128 def printable? origin.print_device_id.present? end |
#tax_groups ⇒ Object
79 80 81 |
# File 'app/models/billing/bill.rb', line 79 def tax_groups billable.try(:tax_groups) end |