billing 0.0.4 → 0.0.5a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/billing/{account.rb → bill.rb} +40 -34
  3. data/app/models/billing/charge.rb +25 -11
  4. data/app/models/billing/modifier.rb +5 -5
  5. data/app/models/billing/origin.rb +7 -2
  6. data/app/models/billing/payment.rb +8 -11
  7. data/app/models/billing/payment_with_type.rb +3 -9
  8. data/app/models/billing/report.rb +29 -13
  9. data/app/models/billing/room_transfer.rb +4 -0
  10. data/app/models/concerns/billing/{account_item.rb → bill_item.rb} +5 -6
  11. data/app/models/concerns/billing/bill_text_parser.rb +18 -0
  12. data/config/initializers/money.rb +67 -0
  13. data/config/routes.rb +1 -6
  14. data/db/migrate/20140803073707_rename_billing_account_to_bill.rb +8 -0
  15. data/db/migrate/20140804065726_add_qty_to_billing_charge.rb +5 -0
  16. data/db/migrate/20140804070517_add_tax_ratio_to_billing_charge.rb +5 -0
  17. data/db/migrate/20141001185321_add_transfer_device_to_billing_origin.rb +5 -0
  18. data/db/migrate/20141027235427_add_f_amount_to_billing_report.rb +7 -0
  19. data/lib/billing.rb +0 -2
  20. data/lib/billing/billable.rb +3 -3
  21. data/lib/billing/engine.rb +3 -0
  22. data/lib/billing/version.rb +1 -1
  23. data/lib/collection_proxy_wild.rb +9 -0
  24. data/test/dummy/config/routes.rb +1 -3
  25. data/test/dummy/db/development.sqlite3 +0 -0
  26. data/test/dummy/db/schema.rb +23 -17
  27. data/test/dummy/db/test.sqlite3 +0 -0
  28. data/test/dummy/log/development.log +8144 -0
  29. data/test/dummy/log/test.log +64325 -0
  30. data/test/fixtures/billing/{accounts.yml → bills.yml} +0 -0
  31. data/test/fixtures/billing/charges.yml +2 -2
  32. data/test/fixtures/billing/modifiers.yml +2 -2
  33. data/test/fixtures/billing/payments.yml +2 -2
  34. data/test/models/billing/bill_test.rb +76 -0
  35. data/test/models/billing/charge_test.rb +13 -6
  36. data/test/models/billing/modifier_test.rb +2 -2
  37. data/test/models/billing/payment_test.rb +12 -12
  38. metadata +20 -58
  39. data/app/assets/javascripts/billing/accounts.js +0 -2
  40. data/app/assets/javascripts/billing/application.js +0 -13
  41. data/app/assets/javascripts/billing/charges.js +0 -2
  42. data/app/assets/javascripts/billing/modifiers.js +0 -2
  43. data/app/assets/stylesheets/billing/accounts.css +0 -4
  44. data/app/assets/stylesheets/billing/application.css +0 -15
  45. data/app/assets/stylesheets/billing/charges.css +0 -4
  46. data/app/assets/stylesheets/billing/modifiers.css +0 -4
  47. data/app/assets/stylesheets/billing/payments.css +0 -4
  48. data/app/controllers/billing/accounts_controller.rb +0 -29
  49. data/app/controllers/billing/application_controller.rb +0 -22
  50. data/app/controllers/billing/charges_controller.rb +0 -29
  51. data/app/controllers/billing/modifiers_controller.rb +0 -29
  52. data/app/controllers/billing/payments_controller.rb +0 -29
  53. data/app/helpers/billing/accounts_helper.rb +0 -4
  54. data/app/helpers/billing/application_helper.rb +0 -4
  55. data/app/helpers/billing/charges_helper.rb +0 -4
  56. data/app/helpers/billing/modifiers_helper.rb +0 -4
  57. data/app/helpers/billing/payments_helper.rb +0 -4
  58. data/app/views/billing/accounts/index.html.erb +0 -7
  59. data/app/views/billing/accounts/new.html.erb +0 -8
  60. data/app/views/billing/accounts/show.html.erb +0 -29
  61. data/app/views/billing/application/index.html.erb +0 -3
  62. data/app/views/billing/charges/new.html.erb +0 -12
  63. data/app/views/billing/modifiers/new.html.erb +0 -18
  64. data/app/views/billing/payments/new.html.erb +0 -11
  65. data/app/views/layouts/billing/application.html.erb +0 -14
  66. data/lib/billing/mapping.rb +0 -32
  67. data/lib/billing/routes.rb +0 -16
  68. data/test/controllers/billing/accounts_controller_test.rb +0 -19
  69. data/test/controllers/billing/charges_controller_test.rb +0 -16
  70. data/test/controllers/billing/modifiers_controller_test.rb +0 -16
  71. data/test/controllers/billing/payments_controller_test.rb +0 -16
  72. data/test/helpers/billing/accounts_helper_test.rb +0 -6
  73. data/test/helpers/billing/charges_helper_test.rb +0 -6
  74. data/test/helpers/billing/modifiers_helper_test.rb +0 -6
  75. data/test/helpers/billing/payments_helper_test.rb +0 -6
  76. data/test/integration/navigation_test.rb +0 -10
  77. data/test/models/billing/account_test.rb +0 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6a8b7a29cfa69d401eb731dbb4dcc67a9016d5e
4
- data.tar.gz: 4ef3454d28c7e0b42f9bb55108131baad90d7ef4
3
+ metadata.gz: 2fa427a04690d7629d0a08954514d57f5be1d9b7
4
+ data.tar.gz: dac8e6fb5fcbf41022da2c731a99ad83d5ddab8c
5
5
  SHA512:
6
- metadata.gz: 1c2f6ff8668e4f23630342d787596721706900dc4dfe9b2aa5f33552774fa42f6f165912b456ec220d0866fe68f9bb06ceb64ba79bb4c52d3a3f3a5a361d8d5f
7
- data.tar.gz: 5e39901f8155e9a73206311bd4bea98417856e366456868579cc2be1ee3717f660c3cb625ac445e9321fee0317ae55fa587dc13d39756bd9c17c14ddae0255e0
6
+ metadata.gz: 0401503350829e7ed2f468740b26ddbf2214187d3daa393292347c080f90a29eba53a175364b4cda0050eff04f0197b3973a80ba8e35eb28777095c53c625590
7
+ data.tar.gz: 6ae75a0cd7c7878501c38982837d39ce48c1684f5d1421e1b9fa5f004a2afda73be696f68f6f05bb013a4cc9d0c693089b2472c28dc62850ca7d8d9dea2f66e6
@@ -1,5 +1,5 @@
1
1
  module Billing
2
- class Account < ActiveRecord::Base
2
+ class Bill < ActiveRecord::Base
3
3
  acts_as_paranoid if respond_to?(:acts_as_paranoid)
4
4
  has_paper_trail class_name: 'Billing::Version' if respond_to?(:has_paper_trail)
5
5
 
@@ -11,11 +11,11 @@ module Billing
11
11
  monetize :balance_cents
12
12
 
13
13
  belongs_to :billable, polymorphic: true
14
- has_many :charges, inverse_of: :account, dependent: :destroy
15
- has_many :modifiers, inverse_of: :account, dependent: :destroy
16
- has_many :payments, inverse_of: :account, dependent: :restrict_with_error
17
- belongs_to :origin, inverse_of: :accounts
18
- belongs_to :report, inverse_of: :accounts
14
+ has_many :charges, inverse_of: :bill, dependent: :destroy
15
+ has_many :modifiers, inverse_of: :bill, dependent: :destroy
16
+ has_many :payments, inverse_of: :bill, dependent: :restrict_with_error
17
+ belongs_to :origin, inverse_of: :bills
18
+ belongs_to :report, inverse_of: :bills
19
19
 
20
20
  if defined? Extface
21
21
  belongs_to :extface_job, class_name: 'Extface::Job'
@@ -28,11 +28,14 @@ module Billing
28
28
  scope :unpaid, -> { where(arel_table[:balance_cents].lt(0)) }
29
29
  scope :open, -> { where.not(balance_cents: 0) }
30
30
  scope :partially_paid, -> { where.not( payments_sum_cents: 0, balance_cents: 0 ) }
31
+ scope :for_report, -> { where(balance_cents: 0 ,report_id: nil) }
31
32
 
32
- before_validation :update_sumaries
33
-
34
- before_save on: :create do
35
- self.number = "#{billable.id}:#{billable.billing_accounts.count}"
33
+ before_validation do
34
+ update_sumaries
35
+ self.origin = payments.first.try(:origin) unless origin.present? or payments.many?
36
+ end
37
+ before_create do
38
+ self.number = "#{billable.id}:#{billable.billing_bills.count}"
36
39
  self.name = "B:#{number}" if name.nil?
37
40
  end
38
41
  before_save :perform_autofin, if: :becomes_paid?
@@ -45,18 +48,15 @@ module Billing
45
48
  :payments_of_diff_fiscalization?, :multiple_cash_payments?, if: :has_payments?
46
49
 
47
50
  def charge(*args)
48
- c = charges.new Charge.args(*args)
49
- c if c.save
51
+ charges.wild *args
50
52
  end
51
53
 
52
54
  def modify(*args)
53
- m = modifiers.new Modifier.args(*args)
54
- m if m.save
55
+ modifiers.wild *args
55
56
  end
56
57
 
57
58
  def pay(*args)
58
- p = build_typed_payment Payment.args(*args)
59
- p if p.save
59
+ payments.wild *args
60
60
  end
61
61
 
62
62
  def modifier_items
@@ -64,11 +64,11 @@ module Billing
64
64
  end
65
65
 
66
66
  def payment_types
67
- billable.try(:billing_payment_types) || Billing::PaymentType.all
67
+ billable.try(:billing_payment_types) #|| Billing::PaymentType.all
68
68
  end
69
69
 
70
70
  def origins
71
- billable.try(:billing_origins) || Billing::Origin.all
71
+ billable.try(:billing_origins) #|| Billing::Origin.all
72
72
  end
73
73
 
74
74
  def has_payments?
@@ -80,34 +80,39 @@ module Billing
80
80
  end
81
81
 
82
82
  def build_typed_payment(attributes = {})
83
- payments.new(attributes.merge(type: origin.try(:payment_model) || 'Billing::PaymentWithType'))
83
+ payment_origin = attributes[:origin] || origins.find_by_id(attributes[:origin_id])
84
+ payments.new(attributes.merge(type: (payment_origin || origin).try(:payment_model) || 'Billing::PaymentWithType'))
84
85
  end
85
86
 
86
87
  def fiscalize #TODO test
87
- extface_job = origin.fiscal_device.fiscalize(self) if fiscalizable? && origin.try(:fiscal_device)
88
- extface_job if save
88
+ self.extface_job = origin.fiscal_device.fiscalize(self) if fiscalizable? && origin.try(:fiscal_device)
89
+ self.extface_job if save
89
90
  end
90
91
 
91
92
  private
92
93
  def calculate_modifiers
94
+ charges_a = charges.to_a
93
95
  @modifier_items = ModifierItems.new.tap() do |items|
94
- modifiers.each do |modifier|
95
- if charge = modifier.charge
96
- charge.value = modifier.percent_ratio.nil? ? modifier.fixed_value : (charge.price * modifier.percent_ratio)
97
- items << Charge.new(price: charge.value, chargable: charge)
98
- else
99
- items << Charge.new(price: modifier.percent_ratio.nil? ? modifier.fixed_value : (charges.to_a.sum(&:price).to_money * modifier.percent_ratio))
100
- end
96
+ modifiers.select{ |m| m.charge.present? }.each do |charge_modifier|
97
+ charge = charges_a.find{ |c| c == charge_modifier.charge }
98
+ mod_value = charge_modifier.percent_ratio.nil? ? charge_modifier.fixed_value : (charge_modifier.charge.price * charge_modifier.percent_ratio)
99
+ charge.value = charge.price + mod_value
100
+ #p charge.value
101
+ #p "-"
102
+ items << Charge.new(price: mod_value, chargable: charge)
103
+ end
104
+ modifiers.select{ |m| m.charge.nil? }.each do |global_modifier|
105
+ items << Charge.new(price: global_modifier.percent_ratio.nil? ? global_modifier.fixed_value : (charges_a.sum(&:value).to_money * global_modifier.percent_ratio))
101
106
  end
102
107
  end
103
108
  end
104
109
  def update_sumaries
105
- self.charges_sum = charges.to_a.sum(&:price).to_money
106
110
  calculate_modifiers
107
- self.discounts_sum = -@modifier_items.discounts.sum(&:price).to_money
108
- self.surcharges_sum = @modifier_items.surcharges.sum(&:price).to_money
109
- self.payments_sum = payments.to_a.sum(&:value).to_money
110
- self.total = charges_sum + surcharges_sum - discounts_sum
111
+ self.charges_sum = charges.to_a.sum(0.to_money, &:value).to_money
112
+ self.discounts_sum = @modifier_items.discounts.sum(0.to_money, &:price).to_money
113
+ self.surcharges_sum = @modifier_items.surcharges.sum(0.to_money, &:price).to_money
114
+ self.payments_sum = payments.to_a.sum(0.to_money, &:value).to_money
115
+ self.total = charges.to_a.sum(0.to_money, &:price) + surcharges_sum + discounts_sum
111
116
  self.balance = payments_sum - total
112
117
  end
113
118
 
@@ -138,7 +143,8 @@ module Billing
138
143
  end
139
144
 
140
145
  def fiscalizable?
141
- payments.select(&:fiscal?)
146
+ payments.select(&:fiscal?).any?
142
147
  end
148
+
143
149
  end
144
150
  end
@@ -1,34 +1,48 @@
1
1
  module Billing
2
2
  class Charge < ActiveRecord::Base
3
- include AccountItem
4
- belongs_to :account, inverse_of: :charges, validate: true
3
+ include BillItem
4
+
5
+ attr_accessor :tax_group, :plu, :department
6
+
7
+ belongs_to :bill, inverse_of: :charges, validate: true
5
8
  belongs_to :chargable, polymorphic: true
6
9
  belongs_to :origin, inverse_of: :charges
7
10
  has_one :modifier, inverse_of: :charge
8
11
 
9
- monetize :price_cents
12
+ monetize :price_cents, with_model_currency: :price_currency
10
13
  monetize :value_cents
11
14
 
12
- delegate :paid?, to: :account
15
+ delegate :paid?, to: :bill
13
16
 
14
- scope :unpaid, -> { joins(:account).where.not(billing_accounts: { balance_cents: 0}) }
15
- scope :paid, -> { joins(:account).where(billing_accounts: { balance_cents: 0}) }
17
+ scope :unpaid, -> { joins(:bill).where.not(billing_bills: { balance_cents: 0}) }
18
+ scope :paid, -> { joins(:bill).where(billing_bills: { balance_cents: 0}) }
16
19
  scope :in_period, lambda {|from, to| where(revenue_at: from..to) }
17
20
 
18
21
  validates_presence_of :price
19
22
  validates_numericality_of :value, greater_than_or_equal_to: 0
20
23
 
21
- before_save do
22
- self.value = price unless modifier.present? #FIXME global account modifier lost
24
+ after_initialize do
25
+ self.value = price #unless modifier.present? #bill validation will update modified value
23
26
  end
24
27
 
25
28
  class << self
26
- def args(*args)
29
+ include Billing::BillTextParser
30
+ def wild_args(*args)
27
31
  case when args.blank? || args.first.is_a?(Hash) then
28
- {}.merge(*args)
32
+ return {}.merge(*args)
33
+ when args.size == 1 && args.first.is_a?(String) then
34
+ if match = args.shift.match(/(\d+[.,]\d+\*|\d+\*|)(\d+[.,]\d+[A-Z]*|\d+[A-Z]*|)(#\d+|)(@\d+|)([+-]\d+[.,]\d+\%?|[+-]\d+\%?|)(\/\S+|)/)
35
+ qty_s, price_s, plu_s, tax_group_s, mod_s, text = match.captures
36
+ return {
37
+ qty: parse_qty(qty_s),
38
+ price: price_s.to_money,
39
+ plu: parse_plu(plu_s),
40
+ name: parse_text(text)
41
+ }
42
+ end
29
43
  else
30
44
  h = { price: args.shift.to_money }
31
- args.any? ? h.merge(*args) : h
45
+ return args.any? ? h.merge(*args) : h
32
46
  end
33
47
  end
34
48
  end
@@ -1,13 +1,13 @@
1
1
  module Billing
2
2
  class Modifier < ActiveRecord::Base
3
- include AccountItem
4
- belongs_to :account, inverse_of: :modifiers, validate: true
3
+ include BillItem
4
+ belongs_to :bill, inverse_of: :modifiers, validate: true
5
5
  belongs_to :charge, inverse_of: :modifier
6
6
  monetize :fixed_value_cents
7
7
 
8
8
  validate :percent_or_value
9
- validates_uniqueness_of :charge, scope: :account_id, allow_nil: true
10
- validates_uniqueness_of :account, scope: :charge_id
9
+ validates_uniqueness_of :charge, scope: :bill_id, allow_nil: true
10
+ validates_uniqueness_of :bill, scope: :charge_id
11
11
 
12
12
  private
13
13
  def percent_or_value
@@ -16,7 +16,7 @@ module Billing
16
16
  end
17
17
 
18
18
  class << self
19
- def args(*args)
19
+ def wild_args(*args)
20
20
  case when args.blank? || args.first.kind_of?(Hash) then
21
21
  {}.merge(*args)
22
22
  when args.first.kind_of?(String) then
@@ -1,10 +1,11 @@
1
1
  module Billing
2
2
  class Origin < ActiveRecord::Base
3
- has_many :accounts, inverse_of: :origin
3
+ has_many :bills, inverse_of: :origin
4
4
  has_many :charges, inverse_of: :origin
5
- has_many :payments, through: :accounts
5
+ has_many :payments, through: :bills
6
6
  if defined? Extface
7
7
  belongs_to :fiscal_device, ->(o) { where( extfaceable_id: o.master_id ) }, class_name: 'Extface::Device'
8
+ belongs_to :transfer_device, ->(o) { where( extfaceable_id: o.master_id ) }, class_name: 'Extface::Device'
8
9
  end
9
10
 
10
11
  validates_presence_of :name
@@ -13,5 +14,9 @@ module Billing
13
14
  def external_payment?
14
15
  payment_model != Payment::PAYMENT_WITH_TYPE
15
16
  end
17
+
18
+ def room_transfer?
19
+ payment_model == Payment::ROOM_TRANSFER
20
+ end
16
21
  end
17
22
  end
@@ -3,34 +3,31 @@ module Billing
3
3
  PAYMENT_WITH_TYPE = 'Billing::PaymentWithType'.freeze
4
4
  PAYMENT_EXTERNAL = 'Billing::PaymentExternal'.freeze
5
5
  PAYPAL_EXPRESS = 'Billing::PaypalExpress'.freeze
6
- PAYMENT_MODELS = [PAYMENT_WITH_TYPE, PAYMENT_EXTERNAL, PAYPAL_EXPRESS].freeze
6
+ ROOM_TRANSFER = 'Billing::RoomTransfer'.freeze
7
+ PAYMENT_MODELS = [PAYMENT_WITH_TYPE, PAYMENT_EXTERNAL, PAYPAL_EXPRESS, ROOM_TRANSFER].freeze
7
8
 
8
- include AccountItem
9
+ include BillItem
9
10
 
10
11
  attr_writer :origin
11
12
  attr_accessor :origin_id
12
13
  monetize :value_cents
13
14
 
14
- belongs_to :account, inverse_of: :payments, validate: true
15
+ belongs_to :bill, inverse_of: :payments, validate: true
15
16
 
16
17
  scope :in_period, lambda {|from, to| where(created_at: from..to) }
17
- scope :for_report, -> { joins(:account).where(billing_accounts: { balance_cents: 0 ,report_id: nil }) }
18
+ scope :for_report, -> { joins(:bill).where(billing_bills: { balance_cents: 0 ,report_id: nil }) }
18
19
 
19
20
  if defined? Extface
20
21
  belongs_to :extface_job, class_name: 'Extface::Job'
21
22
  end
22
23
 
23
- delegate :billable, to: :account
24
+ delegate :billable, to: :bill, allow_nil: true
24
25
 
25
26
  validates_numericality_of :value, greater_than_or_equal_to: 0
26
27
  validates :type, inclusion: { in: PAYMENT_MODELS }
27
28
 
28
29
  after_initialize on: :create do
29
- self.value = -account.try(:balance) if value.zero?
30
- end
31
-
32
- before_validation do
33
- account.origin = origin unless account.origin and account.payments.many?
30
+ self.value = -bill.try(:balance) if bill && value.zero?
34
31
  end
35
32
 
36
33
  def fiscal?; false; end
@@ -43,7 +40,7 @@ module Billing
43
40
 
44
41
  private
45
42
  class << self
46
- def args(*args)
43
+ def wild_args(*args)
47
44
  h = {}
48
45
  case when args.blank? || args.first.kind_of?(Hash) then
49
46
  args.blank? ? h : h.merge(*args)
@@ -2,6 +2,8 @@ module Billing
2
2
  class PaymentWithType < Payment
3
3
  belongs_to :payment_type, inverse_of: :payments
4
4
 
5
+ delegate :fiscal?, :cash?, to: :payment_type, allow_nil: true
6
+
5
7
  validates_presence_of :payment_type
6
8
  validates :payment_type, inclusion: { in: :payment_types }
7
9
 
@@ -9,20 +11,12 @@ module Billing
9
11
  self.payment_type = default_payment_type unless payment_type
10
12
  end
11
13
 
12
- def fiscal?
13
- payment_type.fiscal
14
- end
15
-
16
- def cash?
17
- payment_type.cash
18
- end
19
-
20
14
  private
21
15
  def default_payment_type
22
16
  if pt = billable.try(:default_payment_type)
23
17
  pt
24
18
  else
25
- account.payment_types.try(:first) unless account.payment_types.many?
19
+ bill.try(:payment_types).try(:first) unless bill.try(:payment_types).try(:many?)
26
20
  end
27
21
  end
28
22
 
@@ -3,26 +3,32 @@ module Billing
3
3
  FISCAL_X_REPORT = 'x_report'.freeze
4
4
  FISCAL_Z_REPORT = 'z_report'.freeze
5
5
  FISCAL_PERIOD_REPORT = 'period_report'.freeze
6
- F_OPERATIONS = [FISCAL_X_REPORT, FISCAL_Z_REPORT, FISCAL_PERIOD_REPORT].freeze
6
+ FISCAL_PAYED_RECVD = 'payed_recvd'.freeze
7
+ F_OPERATIONS = [FISCAL_X_REPORT, FISCAL_Z_REPORT, FISCAL_PERIOD_REPORT, FISCAL_PAYED_RECVD].freeze
7
8
 
8
9
  has_paper_trail class_name: 'Billing::Version'
9
10
  belongs_to :origin, inverse_of: :reports
10
- has_many :accounts, inverse_of: :report, autosave: true
11
+ has_many :bills, inverse_of: :report, autosave: true
11
12
  belongs_to :extface_job, class_name: 'Extface::Job'
12
- has_many :payments, through: :accounts
13
+ has_many :payments, through: :bills
13
14
 
14
15
  monetize :payments_sum_cents
15
16
  monetize :payments_cash_cents
16
17
  monetize :payments_fiscal_cents
18
+ monetize :f_amount_cents
17
19
 
18
20
  validates_presence_of :origin
19
- validates_absence_of :partially_paid_accounts?
21
+ validates_absence_of :partially_paid_bills?
20
22
  validates :f_operation, inclusion: { in: F_OPERATIONS }, allow_nil: true
21
23
  validates_presence_of :f_period_from, :f_period_to, if: :fiscal_period_report?
24
+ validates_inclusion_of :positive_f_period?, in: [true], if: :fiscal_period_report?
25
+ validates_presence_of :f_amount, if: :fiscal_payed_recvd?
22
26
 
23
- before_validation :set_report_to_accounts
27
+ before_validation :set_report_to_bills
24
28
  before_create :update_summary
25
29
 
30
+ scope :in_period, lambda {|from, to| where(created_at: from..to) }
31
+
26
32
 
27
33
  def fiscalization
28
34
  if origin.fiscal_device.present?
@@ -37,14 +43,18 @@ module Billing
37
43
  f_operation == FISCAL_PERIOD_REPORT
38
44
  end
39
45
 
40
- def set_report_to_accounts
41
- self.accounts << origin.accounts.select(&:paid?) if zeroing?
46
+ def fiscal_payed_recvd?
47
+ f_operation == FISCAL_PAYED_RECVD
48
+ end
49
+
50
+ def set_report_to_bills
51
+ self.bills << origin.bills.for_report if zeroing?
42
52
  end
43
53
 
44
54
  def update_summary
45
- self.payments_sum = accounts.to_a.sum(Money.new(0, 'USD'), &:payments_sum)
46
- self.payments_cash = payments.select{ |p| p.try(:cash?) }.sum(Money.new(0, 'USD'), &:value)
47
- self.payments_fiscal = payments.select{ |p| p.try(:fiscal?) }.sum(Money.new(0, 'USD'), &:value)
55
+ self.payments_sum = bills.to_a.sum(Money.new(0, 'USD'), &:payments_sum)
56
+ self.payments_cash = bills.collect(&:payments).flatten.select{ |p| p.try(:cash?) }.sum(Money.new(0, 'USD'), &:value)
57
+ self.payments_fiscal = bills.collect(&:payments).flatten.select{ |p| p.try(:fiscal?) }.sum(Money.new(0, 'USD'), &:value)
48
58
  perform_fiscal_job
49
59
  end
50
60
 
@@ -55,12 +65,18 @@ module Billing
55
65
  when FISCAL_X_REPORT then
56
66
  self.extface_job = origin.fiscal_device.driver.x_report_session
57
67
  when FISCAL_PERIOD_REPORT then
58
- p "period"
68
+ self.extface_job = origin.fiscal_device.driver.period_report_session(f_period_from, f_period_to, f_detailed)
69
+ when FISCAL_PAYED_RECVD then
70
+ self.extface_job = origin.fiscal_device.driver.payed_recv_account(f_amount.to_f)
59
71
  end
60
72
  end
61
73
 
62
- def partially_paid_accounts?
63
- accounts.partially_paid.any?
74
+ def partially_paid_bills?
75
+ bills.partially_paid.any?
76
+ end
77
+
78
+ def positive_f_period?
79
+ f_period_from < f_period_to if f_period_from && f_period_to
64
80
  end
65
81
  end
66
82
  end
@@ -0,0 +1,4 @@
1
+ module Billing
2
+ class RoomTransfer < Payment
3
+ end
4
+ end
@@ -1,17 +1,16 @@
1
1
  module Billing
2
- module AccountItem
2
+ module BillItem
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
6
  acts_as_paranoid if respond_to?(:acts_as_paranoid)
7
7
  has_paper_trail class_name: 'Billing::Version' if respond_to?(:has_paper_trail)
8
8
 
9
- delegate :save, to: :account, prefix: :account
10
- delegate :origins, :payment_types, to: :account
9
+ delegate :save, to: :bill, prefix: :bill
10
+ delegate :origins, :payment_types, to: :bill
11
11
 
12
- after_save :account_save
13
-
14
- validates_presence_of :account
12
+ after_save :bill_save
13
+ after_destroy :bill_save
15
14
  end
16
15
 
17
16
  end