invoicing_payments_processing 1.1.16 → 1.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5cafb07fe19bdb27a26ac16c923fef00bcccbcb
4
- data.tar.gz: 5783e53592afe0d64c66fe1f3318b4720adb3b88
3
+ metadata.gz: 2ba80e4b1b4e72baf07ccb19207e125930eadf71
4
+ data.tar.gz: 2df78c09cd1e6b9a467454ab886c484336c57391
5
5
  SHA512:
6
- metadata.gz: 361eff4012d019b0e815febf653fc8c477207f291005648ca575c2e23a821fdd909ddc39cd44c467db7edda2218fb237acda98b6596599ca2195349da2d38be9
7
- data.tar.gz: 25b95340499226f9fa6d46d7cf7b3e64f2a577a6d5427274fd1f557038213ba3d80a05444264ec7941f0641b8cada48354b21f945eaae1922001efc15c180177
6
+ metadata.gz: 119752cad89e007e3a124144e0f27af20be2669867311a36c863227897c1b80108d2938e368aee0fd7f44b5816db05cc0f1aecfd31621997757a470e5c3b40f7
7
+ data.tar.gz: 9e1bc580c20e46a192b1e549325f77a2bd1da9b059e4908bea40a62476f11ec4fb293f2241784c3b1803832d89a6443e6f5dd2e53807cd59f01e741286445cbb
@@ -1,10 +1,11 @@
1
1
  module BlackStack
2
2
  class Balance
3
- attr_accessor :client, :product_code, :amount, :credits
3
+ attr_accessor :client, :product_code, :amount, :credits, :up_time
4
4
 
5
- def initialize(id_client, product_code)
5
+ def initialize(id_client, product_code, up_time=nil)
6
6
  self.client = BlackStack::Client.where(:id => id_client).first
7
7
  self.product_code = product_code
8
+ self.up_time = up_time
8
9
  self.calculate()
9
10
  end
10
11
 
@@ -14,6 +15,9 @@ module BlackStack
14
15
  "from movement with (nolock index(IX_movement__id_client__product_code)) " +
15
16
  "where id_client='#{self.client.id}' " +
16
17
  "and product_code='#{self.product_code}' "
18
+
19
+ q += "and create_time < '#{self.up_time.to_sql}' " if !self.up_time.nil?
20
+
17
21
  row = DB[q].first
18
22
  self.amount = row[:amount].to_f
19
23
  self.credits = row[:credits].to_f
@@ -68,11 +68,11 @@ module BlackStack
68
68
  end
69
69
 
70
70
  # crea un registro en la tabla movment, reduciendo la cantidad de creditos con saldo importe 0, para el producto indicado en product_code.
71
- def adjustment(product_code, adjustment_amount=0, adjustment_credits=0, description=nil, type=BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT)
71
+ def adjustment(product_code, adjustment_amount=0, adjustment_credits=0, description=nil, type=BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT, registraton_time=nil)
72
72
  adjust = BlackStack::Movement.new
73
73
  adjust.id = guid()
74
74
  adjust.id_client = self.id
75
- adjust.create_time = now()
75
+ adjust.create_time = registraton_time.nil? ? now() : registraton_time
76
76
  adjust.type = type
77
77
  adjust.description = description.nil? ? 'Adjustment' : description
78
78
  adjust.paypal1_amount = 0
@@ -110,18 +110,18 @@ module BlackStack
110
110
  o.amount = x
111
111
  o.profits_amount = -x
112
112
  o.save
113
-
114
- # if there is negative credits
115
- total_credits = 0.to_f - BlackStack::Balance.new(self.id, product_code).credits.to_f
116
- total_amount = 0.to_f - BlackStack::Balance.new(self.id, product_code).amount.to_f
117
- sleep(2) # delay to ensure the time of the bonus movement will be later than the time of the consumption movement
118
- if total_credits < 0
119
- self.adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded.')
120
- end
121
-
122
113
  end
123
114
  amount_paid += 0.to_f - o.amount.to_f
124
115
  credits_paid += 0.to_i - o.credits.to_i
116
+
117
+ # if there is negative credits
118
+ total_credits = credits_paid
119
+ total_amount = amount_paid
120
+ if total_credits < 0
121
+ self.adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded.', BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT, o.create_time)
122
+ amount_paid = 0.to_f
123
+ credits_paid = 0.to_i
124
+ end
125
125
  }
126
126
  end
127
127
 
@@ -294,7 +294,7 @@ module BlackStack
294
294
  #
295
295
  BlackStack::Movement.where(:id_invoice_item => item.id).all { |mov|
296
296
  #
297
- mov.expire if mov.expiration_on_next_payment == true
297
+ mov.expire(self.billing_period_from) if mov.expiration_on_next_payment == true
298
298
  #
299
299
  DB.disconnect
300
300
  GC.start
@@ -153,15 +153,15 @@ module BlackStack
153
153
  end
154
154
 
155
155
  # credits expiration
156
- def expire()
156
+ def expire(registraton_time=nil)
157
157
  credits_consumed = self.credits_consumed
158
158
  #
159
159
  self.expiration_start_time = now()
160
160
  self.expiration_tries = self.expiration_tries.to_i + 1
161
161
  self.save
162
162
  #
163
- total_credits = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code).credits.to_f
164
- total_amount = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code).amount.to_f
163
+ total_credits = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code, registraton_time).credits.to_f
164
+ total_amount = 0.to_f - BlackStack::Balance.new(self.client.id, self.product_code, registraton_time).amount.to_f
165
165
  #
166
166
  credits = 0.to_i - self.credits.to_i
167
167
  #
@@ -171,7 +171,7 @@ module BlackStack
171
171
  exp = BlackStack::Movement.new
172
172
  exp.id = guid()
173
173
  exp.id_client = self.client.id
174
- exp.create_time = now()
174
+ exp.create_time = registraton_time.nil? ? now() : registraton_time
175
175
  exp.type = BlackStack::Movement::MOVEMENT_TYPE_EXPIRATION
176
176
  exp.id_user_creator = self.id_user_creator
177
177
  exp.description = 'Expiration Because Allocation is Renewed'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoicing_payments_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.16
4
+ version: 1.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi