billing 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85a0bd23ac0ea7985a56a4a4ffb41890f30b290f
4
- data.tar.gz: f5a71cf981e5bf73c36a797893bd81fcb112cb66
3
+ metadata.gz: 5aaf6345b7a91cc0df617048d93da36900ca1cc4
4
+ data.tar.gz: f99bb213cb8264b2247a9ba5156804397bff807b
5
5
  SHA512:
6
- metadata.gz: e46daa7655ef8825493c364fee6104cc37b37ada9b0ade3ae7e761654abc6408af0f8e57d20da42525bd04c21c658d9a4d07a60a2d06d1cc963cb6ae2efcc882
7
- data.tar.gz: caa0ec0e93301541458037bc462cb6054db3582e44269aeb3f8b64376ddb44d1a8e7ee1138dc16bc4cbaa2eb6d0aef3cf4ab9941fce4603ab1ca533442f91ea2
6
+ metadata.gz: 82b21b36a0434f25cf474e3a5b83967e86fd6d6e2e68d50d5773c4dc0b8ea9fb87f32114403c8f5e017b2590b8d5290e82c72559908d00075b1f4aa3822e9b84
7
+ data.tar.gz: 1c1fcb92d3abd50601794356b4fb6a06dd34f02a8127b72fcb321283f9cdf22710b914751b7943b90ef13d92b843f19f93c351c555de5e2c556bc503f2126250
@@ -1,69 +1,4 @@
1
- module Resque
2
- module Plugins
3
- module ExtfaceLonelyDevice
4
- LOCK_TIMEOUT = 60 * 60 * 24 * 5 # 5 days
5
-
6
- def lock_timeout
7
- Time.now.to_i + LOCK_TIMEOUT + 1
8
- end
9
-
10
- def requeue_interval
11
- self.instance_variable_get(:@requeue_interval) || 1
12
- end
13
-
14
- # Overwrite this method to uniquely identify which mutex should be used
15
- # for a resque worker.
16
- def redis_key(*args)
17
- "extface_"
18
- end
19
-
20
- def can_lock_queue?(*args)
21
- now = Time.now.to_i
22
- key = redis_key(*args)
23
- timeout = lock_timeout
24
-
25
- # Per http://redis.io/commands/setnx
26
- return true if Resque.redis.setnx(key, timeout)
27
- return false if Resque.redis.get(key).to_i > now
28
- return true if Resque.redis.getset(key, timeout).to_i <= now
29
- return false
30
- rescue ActiveRecord::RecordNotFound #redis_key exception
31
- p "Not found!!!"
32
- sleep 1
33
- reenqueue(*args) #will stop if new redis_key exception
34
- end
35
-
36
- def unlock_queue(*args)
37
- Resque.redis.del(redis_key(*args))
38
- end
39
-
40
- def reenqueue(*args)
41
- Resque.enqueue_to(redis_key(*args), self, *args)
42
- end
43
-
44
- def before_perform(*args)
45
- unless can_lock_queue?(*args)
46
- # Sleep so the CPU's rest
47
- sleep(requeue_interval)
48
-
49
- # can't get the lock, so re-enqueue the task
50
- reenqueue(*args)
51
-
52
- # and don't perform
53
- raise Resque::Job::DontPerform
54
- end
55
- end
56
-
57
- def around_perform(*args)
58
- begin
59
- yield
60
- ensure
61
- unlock_queue(*args)
62
- end
63
- end
64
- end
65
- end
66
- end
1
+ require 'rescue/plugins/extface_lonely_device'
67
2
 
68
3
  module Billing
69
4
  class IssueFiscalDoc
@@ -1,69 +1,4 @@
1
- module Resque
2
- module Plugins
3
- module ExtfaceLonelyDevice
4
- LOCK_TIMEOUT = 60 * 60 * 24 * 5 # 5 days
5
-
6
- def lock_timeout
7
- Time.now.to_i + LOCK_TIMEOUT + 1
8
- end
9
-
10
- def requeue_interval
11
- self.instance_variable_get(:@requeue_interval) || 1
12
- end
13
-
14
- # Overwrite this method to uniquely identify which mutex should be used
15
- # for a resque worker.
16
- def redis_key(*args)
17
- "extface_"
18
- end
19
-
20
- def can_lock_queue?(*args)
21
- now = Time.now.to_i
22
- key = redis_key(*args)
23
- timeout = lock_timeout
24
-
25
- # Per http://redis.io/commands/setnx
26
- return true if Resque.redis.setnx(key, timeout)
27
- return false if Resque.redis.get(key).to_i > now
28
- return true if Resque.redis.getset(key, timeout).to_i <= now
29
- return false
30
- rescue ActiveRecord::RecordNotFound #redis_key exception
31
- p "Not found!!!"
32
- sleep 1
33
- reenqueue(*args) #will stop if new redis_key exception
34
- end
35
-
36
- def unlock_queue(*args)
37
- Resque.redis.del(redis_key(*args))
38
- end
39
-
40
- def reenqueue(*args)
41
- Resque.enqueue_to(redis_key(*args), self, *args)
42
- end
43
-
44
- def before_perform(*args)
45
- unless can_lock_queue?(*args)
46
- # Sleep so the CPU's rest
47
- sleep(requeue_interval)
48
-
49
- # can't get the lock, so re-enqueue the task
50
- reenqueue(*args)
51
-
52
- # and don't perform
53
- raise Resque::Job::DontPerform
54
- end
55
- end
56
-
57
- def around_perform(*args)
58
- begin
59
- yield
60
- ensure
61
- unlock_queue(*args)
62
- end
63
- end
64
- end
65
- end
66
- end
1
+ require 'rescue/plugins/extface_lonely_device'
67
2
 
68
3
  module Billing
69
4
  class IssuePrintDoc
@@ -87,24 +22,32 @@ module Billing
87
22
  bill.print_job.runtime do |s|
88
23
  return unless bill.printable?
89
24
  s.notify "Print Doc Start"
90
- s.print "******************************\r\n*"
91
- s.print "Bill ##{bill.number}".center(28)
92
- s.print "*\r\n******************************\r\n"
93
- s.print "------------------------------\r\n"
25
+
26
+ s.print bill.origin.print_header
27
+ s.print "\r\n ****** \r\n"
28
+ s.print "#{bill.name}".truncate(30)
29
+ s.print "\r\n------------------------------\r\n"
94
30
 
95
31
  bill.charges.each do |charge|
96
32
  s.print "#{charge.name.ljust(22)} #{charge.value.to_s.rjust(7)}\r\n"
33
+ if charge.modifier.present?
34
+ s.print " Item modifier: #{charge.modifier.human.to_s.rjust(7)}\r\n"
35
+ end
36
+ end
37
+ if bill.modifiers.any?
38
+ s.print " Global modifier: #{bill.global_modifier_value.to_s.rjust(7)}\r\n"
97
39
  end
98
40
  s.print "-----------\r\n".rjust(32)
99
- s.print "#{bill.total}\r\n".rjust(32)
41
+ s.print "TOTAL: #{bill.total.to_s.rjust(20)}\r\n"
100
42
 
101
43
  # s.print "..............................\r\n"
102
44
  # bill.payments.each do |payment|
103
45
  # s.print "#{payment.payment_type.name.humanize}\r\n"
104
46
  # end
105
-
106
- s.print "\r\n"
107
- s.print "------------------------------\r\n"
47
+
48
+ s.print " ****** \r\n"
49
+ s.print bill.origin.print_footer
50
+ s.print "\r\n------------------------------\r\n"
108
51
  s.print Time.now.strftime("Printed on %m/%d/%Y %T\r\n").rjust(32)
109
52
  s.print "\r\n\r\n\r\n"
110
53
  s.notify "Print Doc End"
@@ -107,7 +107,7 @@ module Billing
107
107
  if global_modifiers.any?
108
108
  gvalue = Money.new(0)
109
109
  global_modifiers.each do |global_modifier|
110
- gvalue += global_modifier.percent_ratio.nil? ? global_modifier.fixed_value : (charges_a.sum(&:value).to_money * global_modifier.percent_ratio)
110
+ gvalue += global_modifier.percent_ratio.nil? ? global_modifier.fixed_value : (charges.to_a.sum(0.to_money, &:value).to_money * global_modifier.percent_ratio)
111
111
  end
112
112
  return gvalue
113
113
  end
@@ -11,6 +11,10 @@ module Billing
11
11
  validates_uniqueness_of :charge, scope: :bill_id, allow_nil: true
12
12
  validates_uniqueness_of :bill, scope: :charge_id
13
13
 
14
+ def human
15
+ percent_ratio.nil? ? fixed_value : "#{(percent_ratio * 100).to_i}%"
16
+ end
17
+
14
18
  private
15
19
  def percent_or_value
16
20
  errors.add :percent_or_value, I18n.t('errors.messages.blank') if percent_ratio.blank? and fixed_value.zero?
@@ -1,11 +1,11 @@
1
1
  module Billing
2
2
  class ModifierItems < Array
3
3
  def discounts
4
- select{ |m| m.price < 0 }
4
+ select{ |m| m.price < 0.to_money }
5
5
  end
6
6
 
7
7
  def surcharges
8
- select{ |m| m.price > 0 }
8
+ select{ |m| m.price > 0.to_money }
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,6 @@
1
+ class AddPrintHeadersToBillingOrigin < ActiveRecord::Migration
2
+ def change
3
+ add_column :billing_origins, :print_header, :string
4
+ add_column :billing_origins, :print_footer, :string
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Billing
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,67 @@
1
+ module Resque
2
+ module Plugins
3
+ module ExtfaceLonelyDevice
4
+ LOCK_TIMEOUT = 60 * 60 * 24 * 5 # 5 days
5
+
6
+ def lock_timeout
7
+ Time.now.to_i + LOCK_TIMEOUT + 1
8
+ end
9
+
10
+ def requeue_interval
11
+ self.instance_variable_get(:@requeue_interval) || 1
12
+ end
13
+
14
+ # Overwrite this method to uniquely identify which mutex should be used
15
+ # for a resque worker.
16
+ def redis_key(*args)
17
+ "extface_"
18
+ end
19
+
20
+ def can_lock_queue?(*args)
21
+ now = Time.now.to_i
22
+ key = redis_key(*args)
23
+ timeout = lock_timeout
24
+
25
+ # Per http://redis.io/commands/setnx
26
+ return true if Resque.redis.setnx(key, timeout)
27
+ return false if Resque.redis.get(key).to_i > now
28
+ return true if Resque.redis.getset(key, timeout).to_i <= now
29
+ return false
30
+ rescue ActiveRecord::RecordNotFound #redis_key exception
31
+ p "Not found!!!"
32
+ sleep 1
33
+ reenqueue(*args) #will stop if new redis_key exception
34
+ end
35
+
36
+ def unlock_queue(*args)
37
+ Resque.redis.del(redis_key(*args))
38
+ end
39
+
40
+ def reenqueue(*args)
41
+ #Resque.enqueue_to(redis_key(*args), self, *args)
42
+ Resque.redis.lpush("queue:#{Resque.queue_from_class(self)}", Resque.encode(class: self, args: args))
43
+ end
44
+
45
+ def before_perform(*args)
46
+ unless can_lock_queue?(*args)
47
+ # Sleep so the CPU's rest
48
+ sleep(requeue_interval)
49
+
50
+ # can't get the lock, so re-enqueue the task
51
+ reenqueue(*args)
52
+
53
+ # and don't perform
54
+ raise Resque::Job::DontPerform
55
+ end
56
+ end
57
+
58
+ def around_perform(*args)
59
+ begin
60
+ yield
61
+ ensure
62
+ unlock_queue(*args)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: billing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vangelov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -177,11 +177,13 @@ files:
177
177
  - db/migrate/20150512040421_add_deleted_at_to_billing_report.rb
178
178
  - db/migrate/20160723160908_add_print_device_to_billing_origin.rb
179
179
  - db/migrate/20160723234233_add_print_job_to_billing_bill.rb
180
+ - db/migrate/20160824235224_add_print_headers_to_billing_origin.rb
180
181
  - lib/billing.rb
181
182
  - lib/billing/billable.rb
182
183
  - lib/billing/engine.rb
183
184
  - lib/billing/version.rb
184
185
  - lib/collection_proxy_wild.rb
186
+ - lib/rescue/plugins/extface_lonely_device.rb
185
187
  - lib/tasks/billing.rake
186
188
  - lib/tasks/billing_tasks.rake
187
189
  - test/billing_test.rb